Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add GraphQL login * Add GraphQL register * Add graphql login/register/delete End2End test * Update from requests * Remove logging * Update to beta.16 * Update * Add error handling * Util function * Update
- Loading branch information
1 parent
71c4745
commit edbff44
Showing
5 changed files
with
229 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
packages/strapi-plugin-users-permissions/test/users-graphql.test.e2e.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
// Test a simple default API with no relations | ||
|
||
const { registerAndLogin } = require('../../../test/helpers/auth'); | ||
const { createAuthRequest } = require('../../../test/helpers/request'); | ||
|
||
let rq; | ||
let graphqlQuery; | ||
let data = {}; | ||
|
||
describe('Test Graphql Users API End to End', () => { | ||
beforeAll(async () => { | ||
const token = await registerAndLogin(); | ||
rq = createAuthRequest(token); | ||
|
||
graphqlQuery = body => { | ||
return rq({ | ||
url: '/graphql', | ||
method: 'POST', | ||
body, | ||
}); | ||
}; | ||
}, 60000); | ||
|
||
describe('Test register and login', () => { | ||
const user = { | ||
username: 'User 1', | ||
email: 'user1@strapi.io', | ||
password: 'test1234', | ||
}; | ||
|
||
test('Register a user', async () => { | ||
const res = await graphqlQuery({ | ||
query: /* GraphQL */ ` | ||
mutation register($input: UserInput!) { | ||
register(input: $input) { | ||
jwt | ||
user { | ||
id | ||
} | ||
} | ||
} | ||
`, | ||
variables: { | ||
input: user, | ||
}, | ||
}); | ||
|
||
const { body } = res; | ||
|
||
expect(res.statusCode).toBe(200); | ||
expect(body).toMatchObject({ | ||
data: { | ||
register: { | ||
jwt: expect.any(String), | ||
user: { | ||
id: expect.any(String), | ||
email: user.email, | ||
}, | ||
}, | ||
}, | ||
}); | ||
data.user = res.body.data.register.user; | ||
}); | ||
|
||
test('Log in a user', async () => { | ||
const res = await graphqlQuery({ | ||
query: /* GraphQL */ ` | ||
mutation login($input: UsersPermissionsLoginInput!) { | ||
login(input: $input) { | ||
jwt | ||
user { | ||
id | ||
} | ||
} | ||
} | ||
`, | ||
variables: { | ||
input: { | ||
identifier: user.username, | ||
password: user.password, | ||
}, | ||
}, | ||
}); | ||
|
||
const { body } = res; | ||
|
||
expect(res.statusCode).toBe(200); | ||
expect(body).toMatchObject({ | ||
data: { | ||
login: { | ||
jwt: expect.any(String), | ||
user: { | ||
id: expect.any(String), | ||
email: user.email, | ||
}, | ||
}, | ||
}, | ||
}); | ||
data.user = res.body.data.login.user; | ||
}); | ||
|
||
test('Delete a user', async () => { | ||
const res = await graphqlQuery({ | ||
query: /* GraphQL */ ` | ||
mutation deleteUser($input: deleteUserInput) { | ||
deleteUser(input: $input) { | ||
user { | ||
} | ||
} | ||
} | ||
`, | ||
variables: { | ||
input: { | ||
where: { | ||
id: data.user.id, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const { body } = res; | ||
|
||
expect(res.statusCode).toBe(200); | ||
expect(body).toMatchObject({ | ||
data: { | ||
deleteUser: { | ||
user: { | ||
email: data.user.email, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters