Relay Spec (#6089)
* Install graphql-relay * Add relayNodeInterface to ParseGraphQLSchema * Add support to global id * Add support to global id in other operations * Fix sort by glboal id * Fix where by global id * Introduce IdWhereInput * Add Relay object identification tests * Client mutation id on createFile mutation * Client mutation id on callCloudCode mutation * Client mutation id on signUp mutation * Client mutation id on logIn mutation * Client mutation id on logOut mutation * Client mutation id on createClass mutation * Client mutation id on updateClass mutation * Client mutation id on deleteClass mutation * Client mutation id on create object mutation * Improve Viewer type * Client mutation id on update object mutation * Client mutation id on delete object mutation * Introducing connections * Fix tests * Add pagination test * Fix file location * Fix postgres tests * Add comments * Tests to calculateSkipAndLimit
This commit is contained in:
committed by
GitHub
parent
67e3c33ffe
commit
a9066e20dc
@@ -54,8 +54,14 @@ describe('AuthenticationProviders', function() {
|
||||
Promise.prototype.constructor
|
||||
);
|
||||
jequal(validateAppIdPromise.constructor, Promise.prototype.constructor);
|
||||
validateAuthDataPromise.then(() => {}, () => {});
|
||||
validateAppIdPromise.then(() => {}, () => {});
|
||||
validateAuthDataPromise.then(
|
||||
() => {},
|
||||
() => {}
|
||||
);
|
||||
validateAppIdPromise.then(
|
||||
() => {},
|
||||
() => {}
|
||||
);
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
@@ -97,7 +97,11 @@ describe('parseObjectToMongoObjectForCreate', () => {
|
||||
const lng3 = 65;
|
||||
const polygon = {
|
||||
__type: 'Polygon',
|
||||
coordinates: [[lat1, lng1], [lat2, lng2], [lat3, lng3]],
|
||||
coordinates: [
|
||||
[lat1, lng1],
|
||||
[lat2, lng2],
|
||||
[lat3, lng3],
|
||||
],
|
||||
};
|
||||
const out = transform.parseObjectToMongoObjectForCreate(
|
||||
null,
|
||||
@@ -107,7 +111,12 @@ describe('parseObjectToMongoObjectForCreate', () => {
|
||||
}
|
||||
);
|
||||
expect(out.location.coordinates).toEqual([
|
||||
[[lng1, lat1], [lng2, lat2], [lng3, lat3], [lng1, lat1]],
|
||||
[
|
||||
[lng1, lat1],
|
||||
[lng2, lat2],
|
||||
[lng3, lat3],
|
||||
[lng1, lat1],
|
||||
],
|
||||
]);
|
||||
done();
|
||||
});
|
||||
@@ -217,7 +226,15 @@ describe('parseObjectToMongoObjectForCreate', () => {
|
||||
const lng = 45;
|
||||
// Mongo stores polygon in WGS84 lng/lat
|
||||
const input = {
|
||||
location: { type: 'Polygon', coordinates: [[[lat, lng], [lat, lng]]] },
|
||||
location: {
|
||||
type: 'Polygon',
|
||||
coordinates: [
|
||||
[
|
||||
[lat, lng],
|
||||
[lat, lng],
|
||||
],
|
||||
],
|
||||
},
|
||||
};
|
||||
const output = transform.mongoObjectToParseObject(null, input, {
|
||||
fields: { location: { type: 'Polygon' } },
|
||||
@@ -225,7 +242,10 @@ describe('parseObjectToMongoObjectForCreate', () => {
|
||||
expect(typeof output.location).toEqual('object');
|
||||
expect(output.location).toEqual({
|
||||
__type: 'Polygon',
|
||||
coordinates: [[lng, lat], [lng, lat]],
|
||||
coordinates: [
|
||||
[lng, lat],
|
||||
[lng, lat],
|
||||
],
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
158
spec/graphQLObjectsQueries.js
Normal file
158
spec/graphQLObjectsQueries.js
Normal file
@@ -0,0 +1,158 @@
|
||||
const { offsetToCursor } = require('graphql-relay');
|
||||
const {
|
||||
calculateSkipAndLimit,
|
||||
} = require('../lib/GraphQL/helpers/objectsQueries');
|
||||
|
||||
describe('GraphQL objectsQueries', () => {
|
||||
describe('calculateSkipAndLimit', () => {
|
||||
it('should fail with invalid params', () => {
|
||||
expect(() => calculateSkipAndLimit(-1)).toThrow(
|
||||
jasmine.stringMatching('Skip should be a positive number')
|
||||
);
|
||||
expect(() => calculateSkipAndLimit(1, -1)).toThrow(
|
||||
jasmine.stringMatching('First should be a positive number')
|
||||
);
|
||||
expect(() => calculateSkipAndLimit(1, 1, offsetToCursor(-1))).toThrow(
|
||||
jasmine.stringMatching('After is not a valid curso')
|
||||
);
|
||||
expect(() => calculateSkipAndLimit(1, 1, offsetToCursor(1), -1)).toThrow(
|
||||
jasmine.stringMatching('Last should be a positive number')
|
||||
);
|
||||
expect(() =>
|
||||
calculateSkipAndLimit(1, 1, offsetToCursor(1), 1, offsetToCursor(-1))
|
||||
).toThrow(jasmine.stringMatching('Before is not a valid curso'));
|
||||
});
|
||||
|
||||
it('should work only with skip', () => {
|
||||
expect(calculateSkipAndLimit(10)).toEqual({
|
||||
skip: 10,
|
||||
limit: undefined,
|
||||
needToPreCount: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('should work only with after', () => {
|
||||
expect(
|
||||
calculateSkipAndLimit(undefined, undefined, offsetToCursor(9))
|
||||
).toEqual({
|
||||
skip: 10,
|
||||
limit: undefined,
|
||||
needToPreCount: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('should work with limit and after', () => {
|
||||
expect(calculateSkipAndLimit(10, undefined, offsetToCursor(9))).toEqual({
|
||||
skip: 20,
|
||||
limit: undefined,
|
||||
needToPreCount: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('first alone should set the limit', () => {
|
||||
expect(calculateSkipAndLimit(10, 30, offsetToCursor(9))).toEqual({
|
||||
skip: 20,
|
||||
limit: 30,
|
||||
needToPreCount: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('if before cursor is less than skipped items, no objects will be returned', () => {
|
||||
expect(
|
||||
calculateSkipAndLimit(
|
||||
10,
|
||||
30,
|
||||
offsetToCursor(9),
|
||||
undefined,
|
||||
offsetToCursor(5)
|
||||
)
|
||||
).toEqual({
|
||||
skip: 20,
|
||||
limit: 0,
|
||||
needToPreCount: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('if before cursor is greater than returned objects set by limit, nothing is changed', () => {
|
||||
expect(
|
||||
calculateSkipAndLimit(
|
||||
10,
|
||||
30,
|
||||
offsetToCursor(9),
|
||||
undefined,
|
||||
offsetToCursor(100)
|
||||
)
|
||||
).toEqual({
|
||||
skip: 20,
|
||||
limit: 30,
|
||||
needToPreCount: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('if before cursor is less than returned objects set by limit, limit is adjusted', () => {
|
||||
expect(
|
||||
calculateSkipAndLimit(
|
||||
10,
|
||||
30,
|
||||
offsetToCursor(9),
|
||||
undefined,
|
||||
offsetToCursor(40)
|
||||
)
|
||||
).toEqual({
|
||||
skip: 20,
|
||||
limit: 20,
|
||||
needToPreCount: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('last should work alone but requires pre count', () => {
|
||||
expect(
|
||||
calculateSkipAndLimit(undefined, undefined, undefined, 10)
|
||||
).toEqual({
|
||||
skip: undefined,
|
||||
limit: 10,
|
||||
needToPreCount: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('last should be adjusted to max limit', () => {
|
||||
expect(
|
||||
calculateSkipAndLimit(undefined, undefined, undefined, 10, undefined, 5)
|
||||
).toEqual({
|
||||
skip: undefined,
|
||||
limit: 5,
|
||||
needToPreCount: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('no objects will be returned if last is equal to 0', () => {
|
||||
expect(calculateSkipAndLimit(undefined, undefined, undefined, 0)).toEqual(
|
||||
{
|
||||
skip: undefined,
|
||||
limit: 0,
|
||||
needToPreCount: false,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('nothing changes if last is bigger than the calculared limit', () => {
|
||||
expect(
|
||||
calculateSkipAndLimit(10, 30, offsetToCursor(9), 30, offsetToCursor(40))
|
||||
).toEqual({
|
||||
skip: 20,
|
||||
limit: 20,
|
||||
needToPreCount: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('If last is small than limit, new limit is calculated', () => {
|
||||
expect(
|
||||
calculateSkipAndLimit(10, 30, offsetToCursor(9), 10, offsetToCursor(40))
|
||||
).toEqual({
|
||||
skip: 30,
|
||||
limit: 10,
|
||||
needToPreCount: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user