Skip to content

Commit

Permalink
test(graphql-transformers-e2e-tests): fix typo on mutation functions (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
SwaySway authored May 29, 2020
1 parent 15eac84 commit 709491f
Showing 1 changed file with 47 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,8 @@ test('test that group is only allowed to listen to subscriptions and listen to o
updatedAt
}
}
`});
`,
});
const subscription = observer.subscribe((event: any) => {
const member = event.data.onCreateMember;
subscription.unsubscribe();
Expand All @@ -821,45 +822,49 @@ test('test that group is only allowed to listen to subscriptions and listen to o
});

test('authorized group is allowed to listen to onUpdate', async done => {
const memberID = '001'
const memberID = '001';
const memberName = 'newUsername';
const observer = GRAPHQL_CLIENT_2.subscribe({
query: gql`
subscription OnUpdateMember {
onUpdateMember {
id
name
createdAt
updatedAt
subscription OnUpdateMember {
onUpdateMember {
id
name
createdAt
updatedAt
}
}
}`});
const subscription = observer.subscribe( (event: any) => {
const subResponse = event.data.onUpdateMember;
subscription.unsubscribe();
expect(subResponse).toBeDefined();
expect(subResponse.id).toEqual(memberID);
expect(subResponse.name).toEqual(memberName);
done();
});
await new Promise(res => setTimeout(() => res(), SUBSCRIPTION_DELAY));
// user that is authorized creates the update the mutation
updateMember(GRAPHQL_CLIENT_1, { id: memberID, name: memberName });
`,
});
const subscription = observer.subscribe((event: any) => {
const subResponse = event.data.onUpdateMember;
subscription.unsubscribe();
expect(subResponse).toBeDefined();
expect(subResponse.id).toEqual(memberID);
expect(subResponse.name).toEqual(memberName);
done();
});
await new Promise(res => setTimeout(() => res(), SUBSCRIPTION_DELAY));
// user that is authorized creates the update the mutation
updateMember(GRAPHQL_CLIENT_1, { id: memberID, name: memberName });
});

test('authoirzed group is allowed to listen to onDelete', async done => {
const memberID = '001';
const memberName = 'newUsername';
const observer = GRAPHQL_CLIENT_2.subscribe({
query: gql`
subscription OnDeleteMember {
onDeleteMember {
id
name
createdAt
updatedAt
subscription OnDeleteMember {
onDeleteMember {
id
name
createdAt
updatedAt
}
}
}`});
const subscription = observer.subscribe( (event: any) => {
`,
});
const subscription = observer.subscribe((event: any) => {
const subResponse = event.data.onDeleteMember;
subscription.unsubscribe();
expect(subResponse).toBeDefined();
Expand Down Expand Up @@ -1020,30 +1025,30 @@ async function createMember(client: AWSAppSyncClient<any>, input: MemberInput) {

async function updateMember(client: AWSAppSyncClient<any>, input: MemberInput) {
const request = gql`
mutation UpdateTimeMember(
$input: UpdateTimeMemberInput! ) {
updateTimeMember(input: $input) {
mutation UpdateMember($input: UpdateMemberInput!) {
updateMember(input: $input) {
id
name
createdAt
updatedAt
}
}`;
return await client.mutate({ mutation: request, variables: { input }});
}
`;
return await client.mutate({ mutation: request, variables: { input } });
}

async function deleteMember(client: AWSAppSyncClient<any>, input: MemberInput) {
const request = gql`
mutation DeleteTimeMember(
$input: DeleteTimeMemberInput! ) {
deleteTimeMember(input: $input) {
id
name
createdAt
updatedAt
mutation DeleteMember($input: DeleteMemberInput!) {
deleteMember(input: $input) {
id
name
createdAt
updatedAt
}
}
}`;
return await client.mutate({ mutation: request, variables: { input }})
`;
return await client.mutate({ mutation: request, variables: { input } });
}

async function createStudent(client: AWSAppSyncClient<any>, input: CreateStudentInput) {
Expand Down

0 comments on commit 709491f

Please sign in to comment.