|
|
|
@ -1,3 +1,5 @@ |
|
|
|
import 'whatwg-fetch'; |
|
|
|
|
|
|
|
const LocalStorage = require('storage_manager/model/LocalStorage'); |
|
|
|
const RemoteStorage = require('storage_manager/model/RemoteStorage'); |
|
|
|
|
|
|
|
@ -57,6 +59,12 @@ module.exports = { |
|
|
|
var params = { test: 'testValue' }; |
|
|
|
var storageOptions; |
|
|
|
var data; |
|
|
|
var mockResponse = (body = {}) => { |
|
|
|
return new window.Response(JSON.stringify(body), { |
|
|
|
status: 200, |
|
|
|
headers: { 'Content-type': 'application/json' } |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
beforeEach(() => { |
|
|
|
data = { |
|
|
|
@ -69,44 +77,28 @@ module.exports = { |
|
|
|
params, |
|
|
|
}; |
|
|
|
obj = new RemoteStorage(storageOptions); |
|
|
|
sinon.stub(obj, 'fetch').returns( |
|
|
|
Promise.resolve(mockResponse({data: 1})) |
|
|
|
); |
|
|
|
}); |
|
|
|
|
|
|
|
afterEach(() => { |
|
|
|
$.ajax.restore(); |
|
|
|
obj.fetch.restore(); |
|
|
|
obj = null; |
|
|
|
}); |
|
|
|
|
|
|
|
// Stubbing will not return the original object so
|
|
|
|
// .always will not work
|
|
|
|
it.skip('Store data', () => { |
|
|
|
sinon.stub($, "ajax"); |
|
|
|
|
|
|
|
for(var k in params) |
|
|
|
data[k] = params[k]; |
|
|
|
|
|
|
|
it('Store data', () => { |
|
|
|
obj.store(data); |
|
|
|
$.ajax.calledWithMatch({ |
|
|
|
url: endpointStore, |
|
|
|
data, |
|
|
|
}).should.equal(true); |
|
|
|
const callResult = obj.fetch; |
|
|
|
expect(callResult.called).toEqual(true); |
|
|
|
expect(callResult.firstCall.args[0]).toEqual(endpointStore); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Load data', () => { |
|
|
|
sinon.stub($, "ajax").returns({ |
|
|
|
done() {} |
|
|
|
}); |
|
|
|
var dt = {}; |
|
|
|
var keys = ['item1', 'item2']; |
|
|
|
obj.load(keys); |
|
|
|
dt.keys = keys; |
|
|
|
|
|
|
|
for(var k in params) |
|
|
|
dt[k] = params[k]; |
|
|
|
|
|
|
|
expect($.ajax.calledWithMatch({ |
|
|
|
url: endpointLoad, |
|
|
|
data: dt |
|
|
|
})).toEqual(true); |
|
|
|
obj.load(['item1', 'item2']); |
|
|
|
const callResult = obj.fetch; |
|
|
|
expect(callResult.called).toEqual(true); |
|
|
|
expect(callResult.firstCall.args[0]).toEqual(endpointLoad); |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|