Change-Id: Id58d18d5f9ac2ec16707e35bb7710fbbc914763fchanges/16/16216/4
parent
dd4ea075de
commit
077393c1dd
@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
export function getJsonBody(body) {
|
||||||
|
if(_.isString(body)) {
|
||||||
|
try {
|
||||||
|
return JSON.parse(body);
|
||||||
|
} catch(err) {
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return body;
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
import Vue from 'vue';
|
||||||
|
import VueResource from 'vue-resource';
|
||||||
|
import { getPreferences } from '../../src/api/subscriber';
|
||||||
|
import { assert } from 'chai';
|
||||||
|
|
||||||
|
Vue.use(VueResource);
|
||||||
|
|
||||||
|
|
||||||
|
describe('Subscriber', function(){
|
||||||
|
|
||||||
|
it('should get all subscriber preferences', function(done) {
|
||||||
|
Vue.http.interceptors = [];
|
||||||
|
Vue.http.interceptors.unshift((request, next)=>{
|
||||||
|
next(request.respondWith(JSON.stringify({
|
||||||
|
block_in_mode: false
|
||||||
|
}), {
|
||||||
|
status: 200
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
getPreferences('123').then((result)=>{
|
||||||
|
assert.property(result, 'block_in_mode');
|
||||||
|
assert.isFalse(result.block_in_mode);
|
||||||
|
done();
|
||||||
|
}).catch((err)=>{
|
||||||
|
done(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle a 403 Forbidden while requesting the preferences', function(done) {
|
||||||
|
Vue.http.interceptors = [];
|
||||||
|
Vue.http.interceptors.unshift((request, next)=>{
|
||||||
|
next(request.respondWith(JSON.stringify({
|
||||||
|
message: '403 Forbidden'
|
||||||
|
}), {
|
||||||
|
status: 403
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
getPreferences('123').then(()=>{
|
||||||
|
done(new Error('Test failed'));
|
||||||
|
}).catch((err)=>{
|
||||||
|
assert.equal(err.status, 403);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in new issue