-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(api): Add jest-cucumber in order to support gherkin natural lan…
…guage and migrate the current api e2e tests
- Loading branch information
Showing
12 changed files
with
421 additions
and
149 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,12 @@ | ||
Feature: Password Recovery | ||
|
||
Scenario: An email should be sent if a user is found | ||
Given a user exists with valid credentials | ||
When the user requests password recovery | ||
Then the user should receive a 201 status code | ||
And an email should be sent | ||
|
||
Scenario: No email should be sent if the user is not found | ||
When the user requests password recovery with an invalid email | ||
Then the user should receive a 201 status code | ||
And no email should be sent |
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,18 @@ | ||
Feature: Sign In | ||
|
||
Scenario: A user tries to sign in with non-existing credentials | ||
When a user attempts to sign in with non-existing credentials | ||
Then the user should receive a 401 status code | ||
And the response message should be "Invalid credentials" | ||
|
||
Scenario: A user tries to sign in with an incorrect password | ||
Given a user exists with valid credentials | ||
When a user attempts to sign in with an incorrect password | ||
Then the user should receive a 401 status code | ||
And the response message should be "Invalid credentials" | ||
|
||
Scenario: A user successfully signs in | ||
Given a user exists with valid credentials | ||
When a user attempts to sign in with valid credentials | ||
Then the user should receive a 201 status code | ||
And the access token should be defined |
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,12 @@ | ||
Feature: User Sign Up | ||
|
||
Scenario: A user cannot sign up with an already registered email | ||
Given a user exists with valid credentials | ||
When the user attempts to sign up with the same email | ||
Then the user should receive a 409 status code | ||
And the response message should be "Email already exists" | ||
|
||
Scenario: A user successfully signs up with a new email | ||
When a user attempts to sign up with valid credentials | ||
Then the user should be registered successfully | ||
And the user should have a valid ID and 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { defineFeature, loadFeature } from 'jest-cucumber'; | ||
import { Response } from 'supertest'; | ||
import { User } from '@shared/entities/users/user.entity'; | ||
import { IEmailServiceToken } from '@api/modules/notifications/email/email-service.interface'; | ||
import { MockEmailService } from 'api/test/utils/mocks/mock-email.service'; | ||
import { TestManager } from 'api/test/utils/test-manager'; | ||
|
||
const feature = loadFeature('./test/e2e/features/password-recovery.feature'); | ||
|
||
defineFeature(feature, (test) => { | ||
let testManager: TestManager; | ||
let testUser: User; | ||
let mockEmailService: MockEmailService; | ||
|
||
beforeAll(async () => { | ||
testManager = await TestManager.createTestManager(); | ||
mockEmailService = | ||
testManager.moduleFixture.get<MockEmailService>(IEmailServiceToken); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await testManager.clearDatabase(); | ||
const { user } = await testManager.setUpTestUser(); | ||
testUser = user; | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await testManager.close(); | ||
}); | ||
|
||
test('An email should be sent if a user is found', ({ | ||
given, | ||
when, | ||
then, | ||
and, | ||
}) => { | ||
let response: Response; | ||
|
||
given('a user exists with valid credentials', async () => { | ||
testUser = await testManager.mocks().createUser({ | ||
email: '[email protected]', | ||
password: 'password123', | ||
}); | ||
}); | ||
|
||
when('the user requests password recovery', async () => { | ||
response = await testManager | ||
.request() | ||
.post(`/authentication/recover-password`) | ||
.send({ email: testUser.email }); | ||
}); | ||
|
||
then( | ||
/the user should receive a (\d+) status code/, | ||
async (statusCode: string) => { | ||
expect(response.status).toBe(Number.parseInt(statusCode)); | ||
}, | ||
); | ||
|
||
and('an email should be sent', async () => { | ||
expect(mockEmailService.sendMail).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
test('No email should be sent if the user is not found', ({ | ||
when, | ||
then, | ||
and, | ||
}) => { | ||
let response: Response; | ||
|
||
when( | ||
'the user requests password recovery with an invalid email', | ||
async () => { | ||
response = await testManager | ||
.request() | ||
.post(`/authentication/recover-password`) | ||
.send({ email: '[email protected]' }); | ||
}, | ||
); | ||
|
||
then( | ||
/the user should receive a (\d+) status code/, | ||
async (statusCode: string) => { | ||
expect(response.status).toBe(Number.parseInt(statusCode)); | ||
}, | ||
); | ||
|
||
and('no email should be sent', async () => { | ||
expect(mockEmailService.sendMail).toHaveBeenCalledTimes(0); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.