2019-11-18 22:38:51 +01:00
|
|
|
import { expect } from 'chai';
|
|
|
|
import 'mocha';
|
2021-01-30 22:34:36 +01:00
|
|
|
import { container, Service } from '../../core/container';
|
2019-11-18 22:38:51 +01:00
|
|
|
|
2020-04-10 05:12:14 +02:00
|
|
|
describe('Store Service', function () {
|
2019-11-18 22:38:51 +01:00
|
|
|
this.timeout(10000);
|
|
|
|
|
2019-11-20 22:29:04 +01:00
|
|
|
it('loads saved data', () => {
|
2021-01-30 22:34:36 +01:00
|
|
|
const store: StoreInterface = container.get(Service.STORE);
|
2020-07-25 02:02:37 +02:00
|
|
|
const testData = {
|
2019-11-20 22:29:04 +01:00
|
|
|
something: 'gaga',
|
|
|
|
somethingElse: 0,
|
|
|
|
deepObject: {
|
2020-04-22 01:12:02 +02:00
|
|
|
somethingAsWell: true,
|
2019-11-20 22:29:04 +01:00
|
|
|
somethingNotInJson: undefined,
|
|
|
|
someArray: [
|
|
|
|
'hui',
|
|
|
|
{
|
|
|
|
g: 'h',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const expectedJson = JSON.stringify(testData);
|
2020-07-25 02:02:37 +02:00
|
|
|
return store
|
|
|
|
.save(StoreKey.COOKIES, testData)
|
|
|
|
.then(() => store.load(StoreKey.COOKIES))
|
2019-11-20 22:29:04 +01:00
|
|
|
.then((data) => {
|
|
|
|
expect(JSON.stringify(data)).to.equal(expectedJson, 'store does not save and load data correctly');
|
2020-07-25 02:02:37 +02:00
|
|
|
return store.load(StoreKey.COOKIES);
|
2019-11-20 22:29:04 +01:00
|
|
|
})
|
|
|
|
.then((data) => {
|
2020-04-22 01:12:02 +02:00
|
|
|
expect(JSON.stringify(data)).to.equal(expectedJson, 'store does not load data correctly when loaded twice');
|
2019-11-20 22:29:04 +01:00
|
|
|
});
|
|
|
|
});
|
2019-11-18 22:38:51 +01:00
|
|
|
});
|