Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added deltaset tests #294

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fe17056
Added deltaset tests
May 9, 2018
73e2b83
added new tests for limit and skip and some unit tests
May 16, 2018
40d00ba
skipped tests that use websql to not run on other than html5 and remo…
May 16, 2018
d29b076
removed another .only
May 16, 2018
37555fd
did some refactoring and fixed tests failing for Nativescript and Pho…
May 17, 2018
24e4eef
Fix status code set with nock for failing unit test
thomasconner May 18, 2018
86a15f3
Added deltaset tests
May 9, 2018
f42a244
added new tests for limit and skip and some unit tests
May 16, 2018
b5f1dc9
skipped tests that use websql to not run on other than html5 and remo…
May 16, 2018
0a0ef01
removed another .only
May 16, 2018
a835afa
did some refactoring and fixed tests failing for Nativescript and Pho…
May 17, 2018
4d73ee4
Fix status code set with nock for failing unit test
thomasconner May 18, 2018
6b4e403
added a test for autopagination with skip and limit
May 18, 2018
c679407
fixed conflict
May 18, 2018
45cf5a3
fixing an expectation string and wrong expectation for deltaset test
May 18, 2018
f80ab0a
Added deltaset tests
May 9, 2018
1f3269f
added new tests for limit and skip and some unit tests
May 16, 2018
fcdac57
skipped tests that use websql to not run on other than html5 and remo…
May 16, 2018
8300a14
removed another .only
May 16, 2018
c40500f
did some refactoring and fixed tests failing for Nativescript and Pho…
May 17, 2018
f5080c6
Fix status code set with nock for failing unit test
thomasconner May 18, 2018
dee46f9
after the rebase
May 18, 2018
8ed4b70
removed .only again
May 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 127 additions & 1 deletion src/core/datastore/cachestore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SyncOperation } from './sync';
import { init } from '../kinvey';
import { Query } from '../query';
import { Aggregation } from '../aggregation';
import { KinveyError, NotFoundError, ServerError } from '../errors';
import { KinveyError, NotFoundError, ServerError, BadRequestError } from '../errors';
import { randomString } from '../utils';
import { NetworkRack } from '../request';
import { NodeHttpMiddleware } from '../../node/http';
Expand Down Expand Up @@ -378,6 +378,132 @@ describe('CacheStore', () => {
})
.catch(done);
});

it('should send regular GET request with outdated lastRequest', function (done){
const entity1 = { _id: randomString() };
const entity2 = { _id: randomString() };
const store = new CacheStore(collection, null, { useDeltaSet: true});
const onNextSpy = expect.createSpy();
const lastRequestDate = new Date();
lastRequestDate.setDate(new Date().getDate()-31);

nock(store.client.apiHostname)
.get(`/appdata/${store.client.appKey}/${collection}`)
.reply(200, [entity1, entity2], {
'X-Kinvey-Request-Start': lastRequestDate.toISOString()
});

store.pull()
.then(()=>{
nock(store.client.apiHostname)
.get(`/appdata/${store.client.appKey}/${collection}/_deltaset`)
.query({ since: lastRequestDate.toISOString() })
.reply(400, {debug: "The 'since' timestamp must be within the past 1 days.",
description: "The value specified for one of the request parameters is out of range",
error: "ParameterValueOutOfRange"});

nock(store.client.apiHostname)
.get(`/appdata/${store.client.appKey}/${collection}`)
.reply(200, [entity1, entity2], {
'X-Kinvey-Request-Start': lastRequestDate.toISOString()
});
store.find()
.subscribe(onNextSpy, done, ()=>{
try{
expect(onNextSpy.calls.length).toEqual(2);
expect(onNextSpy.calls[0].arguments).toEqual([[entity1, entity2]]);
expect(onNextSpy.calls[1].arguments).toEqual([[entity1, entity2]]);
done();
} catch (error) {
done(error);
}
})
})
.catch(done);
});

it('should send regular GET request when configuration is missing on the backend', function (done){
const entity1 = { _id: randomString() };
const entity2 = { _id: randomString() };
const store = new CacheStore(collection, null, { useDeltaSet: true});
const onNextSpy = expect.createSpy();
const lastRequestDate = new Date();
const firstNock = nock(store.client.apiHostname)
.get(`/appdata/${store.client.appKey}/${collection}`)
.reply(200, [entity1, entity2], {
'X-Kinvey-Request-Start': lastRequestDate.toISOString()
});

store.pull()
.then(()=>{
firstNock.done();
const secondNock = nock(store.client.apiHostname)
.get(`/appdata/${store.client.appKey}/${collection}/_deltaset`)
.query({ since: lastRequestDate.toISOString() })
.reply(403, {
"error": "MissingConfiguration",
"description": "This feature is not properly configured for this app backend. Please configure it through the console first, or contact support for more information.",
"debug": "This collection has not been configured for Delta Set access."
});

const thirdNock = nock(store.client.apiHostname)
.get(`/appdata/${store.client.appKey}/${collection}`)
.reply(200, [entity1, entity2], {
'X-Kinvey-Request-Start': lastRequestDate.toISOString()
});
store.find()
.subscribe(onNextSpy, done, ()=>{
try{
secondNock.done();
thirdNock.done();
expect(onNextSpy.calls.length).toEqual(2);
expect(onNextSpy.calls[0].arguments).toEqual([[entity1, entity2]]);
expect(onNextSpy.calls[1].arguments).toEqual([[entity1, entity2]]);
done();
} catch (error) {
done(error);
}
})
})
.catch(done);
});

it('should return error if more than 10000 items are changed', function (done){
const entity1 = { _id: randomString() };
const entity2 = { _id: randomString() };
const store = new CacheStore(collection, null, { useDeltaSet: true});
const onNextSpy = expect.createSpy();
const lastRequestDate = new Date();

nock(store.client.apiHostname)
.get(`/appdata/${store.client.appKey}/${collection}`)
.reply(200, [entity1, entity2], {
'X-Kinvey-Request-Start': lastRequestDate.toISOString()
});

store.pull()
.then(()=>{
nock(store.client.apiHostname)
.get(`/appdata/${store.client.appKey}/${collection}/_deltaset`)
.query({ since: lastRequestDate.toISOString() })
.reply(400, {
error: "BadRequest",
description: "Unable to understand request",
debug: "ResultSetSizeExceeded"
});
store.find()
.subscribe(null, (error)=>{
try{
expect(error).toBeA(BadRequestError);
expect(error.debug).toEqual('ResultSetSizeExceeded')
done();
} catch (e) {
done(e);
}
})
})
.catch(done);
});
});

it('should remove entities that no longer exist on the backend from the cache', (done) => {
Expand Down
1 change: 1 addition & 0 deletions test/integration/configs/tests-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

const testsConfig = {
collectionName: 'Books',
deltaCollectionName: 'BooksDelta',
fbEmail: process.env.FACEBOOK_EMAIL,
fbPassword: process.env.FACEBOOK_PASSWORD,
authServiceId: 'decad9197f0f4680a46d902327c5c131'
Expand Down
Loading