Skip to content

Instantly share code, notes, and snippets.

@gcmatheusj
Created February 5, 2020 17:23
Show Gist options
  • Select an option

  • Save gcmatheusj/775247d429ac3eeeaffc71ce73d950aa to your computer and use it in GitHub Desktop.

Select an option

Save gcmatheusj/775247d429ac3eeeaffc71ce73d950aa to your computer and use it in GitHub Desktop.
it('should be able to update account', async () => {
const queryAccountSettings = `
query ($subdomain: String!) {
getAccountSettingsBySubDomain(subdomain: $subdomain) {
id
}
}
`;
const variablesAccountSettings = {
subdomain: 'learn49'
};
const accountSettings = await request(app.getHttpServer())
.post('/graphql')
.send({
query: queryAccountSettings,
variables: variablesAccountSettings
});
const accountSettingsParsed = JSON.parse(accountSettings.text);
const accountId =
accountSettingsParsed.data.getAccountSettingsBySubDomain.id;
const queryAuth = `
mutation($accountId: String!, $UserInput: UserInput!) {
auth(accountId: $accountId, userInput: $UserInput) {
token
}
}
`;
const variablesAuth = {
accountId,
UserInput: {
email: 'user@learn49.com',
passwd: '12345678'
}
};
const auth = await request(app.getHttpServer())
.post('/graphql')
.send({
query: queryAuth,
variables: variablesAuth
});
const authParsed = JSON.parse(auth.text);
const token = authParsed.data.auth.token;
const query = `
mutation ($accountId: String!, $UpdateAccountInput: UpdateAccountInput!) {
updateAccount(accountId: $accountId, updateAccountInput: $UpdateAccountInput){
id
}
}
`;
const variables = {
accountId,
UpdateAccountInput: {
domain: 'learn49.com',
friendlyName: 'Learn49 LMS',
description: 'The Best LMS In The World'
}
};
return request(app.getHttpServer())
.post('/graphql')
.set('Authorization', `Bearer ${token}`)
.send({ query, variables })
.expect(200, {
data: {
updateAccount: {
id: accountId
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment