Skip to content

Commit c2e9e3c

Browse files
committed
graphql tests
1 parent 5674f85 commit c2e9e3c

File tree

7 files changed

+195
-47
lines changed

7 files changed

+195
-47
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
"build": "babel src/ -d lib/ --copy-files",
102102
"watch": "babel --watch src/ -d lib/ --copy-files",
103103
"pretest": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=4.0.4} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} MONGODB_STORAGE_ENGINE=${MONGODB_STORAGE_ENGINE:=mmapv1} mongodb-runner start",
104-
"testonly": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=4.0.4} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} MONGODB_STORAGE_ENGINE=${MONGODB_STORAGE_ENGINE:=mmapv1} TESTING=1 nyc jasmine",
104+
"testonly": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=4.0.4} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} MONGODB_STORAGE_ENGINE=${MONGODB_STORAGE_ENGINE:=mmapv1} TESTING=1 jasmine",
105105
"test": "npm run testonly",
106106
"posttest": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=4.0.4} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} MONGODB_STORAGE_ENGINE=${MONGODB_STORAGE_ENGINE:=mmapv1} mongodb-runner stop",
107107
"coverage": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=4.0.4} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} MONGODB_STORAGE_ENGINE=${MONGODB_STORAGE_ENGINE:=mmapv1} TESTING=1 nyc jasmine",

spec/CloudCode.Validator.spec.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -587,16 +587,10 @@ describe('cloud validator', () => {
587587
expect(obj.get('foo')).toBe('bar');
588588

589589
const query = new Parse.Query('beforeFind');
590-
try {
591-
const first = await query.first({ useMasterKey: true });
592-
expect(first).toBeDefined();
593-
expect(first.id).toBe(obj.id);
594-
done();
595-
} catch (e) {
596-
console.log(e);
597-
console.log(e.code);
598-
throw e;
599-
}
590+
const first = await query.first({ useMasterKey: true });
591+
expect(first).toBeDefined();
592+
expect(first.id).toBe(obj.id);
593+
done();
600594
});
601595

602596
it('basic beforeDelete skipWithMasterKey', async function (done) {

spec/ParseGraphQLServer.spec.js

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6753,7 +6753,62 @@ describe('ParseGraphQLServer', () => {
67536753
});
67546754

67556755
describe('Users Mutations', () => {
6756+
const challengeAdapter = {
6757+
validateAuthData: () => Promise.resolve({ response: { someData: true } }),
6758+
validateAppId: () => Promise.resolve(),
6759+
challenge: () => Promise.resolve({ someData: true }),
6760+
options: { anOption: true },
6761+
};
6762+
6763+
it('should create user and return authData response', async () => {
6764+
parseServer = await global.reconfigureServer({
6765+
publicServerURL: 'http://localhost:13377/parse',
6766+
auth: {
6767+
challengeAdapter,
6768+
},
6769+
});
6770+
const clientMutationId = uuidv4();
6771+
6772+
await parseGraphQLServer.parseGraphQLSchema.databaseController.schemaCache.clear();
6773+
const result = await apolloClient.mutate({
6774+
mutation: gql`
6775+
mutation createUser($input: CreateUserInput!) {
6776+
createUser(input: $input) {
6777+
clientMutationId
6778+
user {
6779+
id
6780+
authDataResponse
6781+
}
6782+
}
6783+
}
6784+
`,
6785+
variables: {
6786+
input: {
6787+
clientMutationId,
6788+
fields: {
6789+
authData: {
6790+
challengeAdapter: {
6791+
id: 'challengeAdapter',
6792+
},
6793+
},
6794+
},
6795+
},
6796+
},
6797+
});
6798+
6799+
expect(result.data.createUser.clientMutationId).toEqual(clientMutationId);
6800+
expect(result.data.createUser.user.authDataResponse).toEqual({
6801+
challengeAdapter: { someData: true },
6802+
});
6803+
});
6804+
67566805
it('should sign user up', async () => {
6806+
parseServer = await global.reconfigureServer({
6807+
publicServerURL: 'http://localhost:13377/parse',
6808+
auth: {
6809+
challengeAdapter,
6810+
},
6811+
});
67576812
const clientMutationId = uuidv4();
67586813
const userSchema = new Parse.Schema('_User');
67596814
userSchema.addString('someField');
@@ -6770,6 +6825,7 @@ describe('ParseGraphQLServer', () => {
67706825
sessionToken
67716826
user {
67726827
someField
6828+
authDataResponse
67736829
aPointer {
67746830
id
67756831
username
@@ -6785,6 +6841,11 @@ describe('ParseGraphQLServer', () => {
67856841
fields: {
67866842
username: 'user1',
67876843
password: 'user1',
6844+
authData: {
6845+
challengeAdapter: {
6846+
id: 'challengeAdapter',
6847+
},
6848+
},
67886849
aPointer: {
67896850
createAndLink: {
67906851
username: 'user2',
@@ -6804,6 +6865,9 @@ describe('ParseGraphQLServer', () => {
68046865
expect(result.data.signUp.viewer.user.aPointer.id).toBeDefined();
68056866
expect(result.data.signUp.viewer.user.aPointer.username).toEqual('user2');
68066867
expect(typeof result.data.signUp.viewer.sessionToken).toBe('string');
6868+
expect(result.data.signUp.viewer.user.authDataResponse).toEqual({
6869+
challengeAdapter: { someData: true },
6870+
});
68076871
});
68086872

68096873
it('should login with user', async () => {
@@ -6812,6 +6876,7 @@ describe('ParseGraphQLServer', () => {
68126876
parseServer = await global.reconfigureServer({
68136877
publicServerURL: 'http://localhost:13377/parse',
68146878
auth: {
6879+
challengeAdapter,
68156880
myAuth: {
68166881
module: global.mockCustomAuthenticator('parse', 'graphql'),
68176882
},
@@ -6831,6 +6896,7 @@ describe('ParseGraphQLServer', () => {
68316896
sessionToken
68326897
user {
68336898
someField
6899+
authDataResponse
68346900
aPointer {
68356901
id
68366902
username
@@ -6844,6 +6910,7 @@ describe('ParseGraphQLServer', () => {
68446910
input: {
68456911
clientMutationId,
68466912
authData: {
6913+
challengeAdapter: { id: 'challengeAdapter' },
68476914
myAuth: {
68486915
id: 'parse',
68496916
password: 'graphql',
@@ -6869,9 +6936,68 @@ describe('ParseGraphQLServer', () => {
68696936
expect(typeof result.data.logInWith.viewer.sessionToken).toBe('string');
68706937
expect(result.data.logInWith.viewer.user.aPointer.id).toBeDefined();
68716938
expect(result.data.logInWith.viewer.user.aPointer.username).toEqual('user2');
6939+
expect(result.data.logInWith.viewer.user.authDataResponse).toEqual({
6940+
challengeAdapter: { someData: true },
6941+
});
6942+
});
6943+
6944+
it('should handle challenge', async () => {
6945+
const clientMutationId = uuidv4();
6946+
6947+
spyOn(challengeAdapter, 'challenge').and.callThrough();
6948+
parseServer = await global.reconfigureServer({
6949+
publicServerURL: 'http://localhost:13377/parse',
6950+
auth: {
6951+
challengeAdapter,
6952+
},
6953+
});
6954+
6955+
const user = new Parse.User();
6956+
await user.save({ username: 'username', password: 'password' });
6957+
6958+
const result = await apolloClient.mutate({
6959+
mutation: gql`
6960+
mutation Challenge($input: ChallengeInput!) {
6961+
challenge(input: $input) {
6962+
clientMutationId
6963+
challengeData
6964+
}
6965+
}
6966+
`,
6967+
variables: {
6968+
input: {
6969+
clientMutationId,
6970+
username: 'username',
6971+
password: 'password',
6972+
challengeData: {
6973+
challengeAdapter: { someChallengeData: true },
6974+
},
6975+
},
6976+
},
6977+
});
6978+
6979+
const challengeCall = challengeAdapter.challenge.calls.argsFor(0);
6980+
expect(challengeAdapter.challenge).toHaveBeenCalledTimes(1);
6981+
expect(challengeCall[0]).toEqual({ someChallengeData: true });
6982+
expect(challengeCall[1] instanceof Parse.User).toBeTruthy();
6983+
expect(challengeCall[1].id).toEqual(user.id);
6984+
expect(challengeCall[2].config).toBeDefined();
6985+
expect(challengeCall[2].auth).toBeDefined();
6986+
expect(challengeCall[2].config.headers).toBeDefined();
6987+
expect(challengeCall[2]).toBeDefined({ anOption: true });
6988+
expect(result.data.challenge.clientMutationId).toEqual(clientMutationId);
6989+
expect(result.data.challenge.challengeData).toEqual({
6990+
challengeAdapter: { someData: true },
6991+
});
68726992
});
68736993

68746994
it('should log the user in', async () => {
6995+
parseServer = await global.reconfigureServer({
6996+
publicServerURL: 'http://localhost:13377/parse',
6997+
auth: {
6998+
challengeAdapter,
6999+
},
7000+
});
68757001
const clientMutationId = uuidv4();
68767002
const user = new Parse.User();
68777003
user.setUsername('user1');
@@ -6888,6 +7014,7 @@ describe('ParseGraphQLServer', () => {
68887014
viewer {
68897015
sessionToken
68907016
user {
7017+
authDataResponse
68917018
someField
68927019
}
68937020
}
@@ -6899,6 +7026,7 @@ describe('ParseGraphQLServer', () => {
68997026
clientMutationId,
69007027
username: 'user1',
69017028
password: 'user1',
7029+
authData: { challengeAdapter: { token: true } },
69027030
},
69037031
},
69047032
});
@@ -6907,6 +7035,9 @@ describe('ParseGraphQLServer', () => {
69077035
expect(result.data.logIn.viewer.sessionToken).toBeDefined();
69087036
expect(result.data.logIn.viewer.user.someField).toEqual('someValue');
69097037
expect(typeof result.data.logIn.viewer.sessionToken).toBe('string');
7038+
expect(result.data.logIn.viewer.user.authDataResponse).toEqual({
7039+
challengeAdapter: { someData: true },
7040+
});
69107041
});
69117042

69127043
it('should log the user out', async () => {

src/Auth.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ const findUsersWithAuthData = (config, authData) => {
373373
};
374374

375375
const hasMutatedAuthData = (authData, userAuthData, config) => {
376+
if (!userAuthData) return { hasMutatedAuthData: true, mutatedAuthData: authData };
376377
const mutatedAuthData = {};
377378
Object.keys(authData).forEach(provider => {
378379
// Anonymous provider is not handled this way

src/GraphQL/loaders/parseClassTypes.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,7 @@ const load = (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseGraphQLCla
141141
...fields,
142142
[field]: {
143143
description: `This is the object ${field}.`,
144-
type:
145-
(className === '_User' && (field === 'username' || field === 'password')) ||
146-
parseClass.fields[field].required
147-
? new GraphQLNonNull(type)
148-
: type,
144+
type: parseClass.fields[field].required ? new GraphQLNonNull(type) : type,
149145
},
150146
};
151147
} else {

0 commit comments

Comments
 (0)