-
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.
check user has been activated in verify token
- Loading branch information
Showing
4 changed files
with
73 additions
and
4 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
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,55 @@ | ||
import { ROLES } from '@api/modules/auth/authorisation/roles.enum'; | ||
import { TestManager } from '../../utils/test-manager'; | ||
import { HttpStatus } from '@nestjs/common'; | ||
import { ApiConfigService } from '@api/modules/config/app-config.service'; | ||
import { JwtService } from '@nestjs/jwt'; | ||
import { TOKEN_TYPE_ENUM } from '@shared/schemas/auth/token-type.schema'; | ||
import { authContract } from '@shared/contracts/auth.contract'; | ||
|
||
//create-user.feature | ||
|
||
describe('Create Users', () => { | ||
let testManager: TestManager; | ||
let apiConfig: ApiConfigService; | ||
let jwtService: JwtService; | ||
|
||
beforeAll(async () => { | ||
testManager = await TestManager.createTestManager(); | ||
apiConfig = testManager.getModule<ApiConfigService>(ApiConfigService); | ||
jwtService = testManager.getModule<JwtService>(JwtService); | ||
}); | ||
|
||
afterEach(async () => { | ||
await testManager.clearDatabase(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await testManager.close(); | ||
}); | ||
|
||
test('A sign-up token should not be valid if the user bound to that token has already been activated', async () => { | ||
// Given a user exists with valid credentials | ||
// But the user has the role partner | ||
|
||
const user = await testManager.mocks().createUser({ | ||
role: ROLES.PARTNER, | ||
email: '[email protected]', | ||
isActive: true, | ||
}); | ||
const { secret, expiresIn } = apiConfig.getJWTConfigByType( | ||
TOKEN_TYPE_ENUM.EMAIL_CONFIRMATION, | ||
); | ||
|
||
const token = jwtService.sign({ id: user.id }, { secret, expiresIn }); | ||
|
||
// When the user creates a new user | ||
|
||
const response = await testManager | ||
.request() | ||
.get(authContract.validateToken.path) | ||
.set('Authorization', `Bearer ${token}`) | ||
.query({ tokenType: TOKEN_TYPE_ENUM.EMAIL_CONFIRMATION }); | ||
|
||
expect(response.status).toBe(HttpStatus.UNAUTHORIZED); | ||
}); | ||
}); |