Created
September 19, 2022 02:32
-
-
Save alexsoyes/77ec2aa063f4a98eb33801b1a94ac6e5 to your computer and use it in GitHub Desktop.
A step definition with Cucumber against login for functionnal testing.
This file contains hidden or 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
import { Before, Then, When } from '@cucumber/cucumber'; | |
import { TestingModule } from '@nestjs/testing'; | |
import { getTestingModule } from '../../apps/core/src/shared/in-memory-orm.module'; | |
import FixturesService from '../../apps/fixtures/src/fixtures.service'; | |
import { AuthModule } from '../../apps/core/src/authentication/auth.module'; | |
import { AuthService } from '../../apps/core/src/authentication/auth.service'; | |
import { PassportModule } from '@nestjs/passport'; | |
import { JwtModule } from '@nestjs/jwt'; | |
import { PermissionsModule } from '../../apps/core/src/authentication/permissions/permissions.module'; | |
let authService: AuthService = null; | |
Before(async () => { | |
const module: TestingModule = await getTestingModule( | |
[FixturesService, AuthService], | |
[], | |
[ | |
AuthModule, | |
PassportModule, | |
JwtModule.register({ | |
secret: 'secret', // @todo env | |
signOptions: { expiresIn: '7d' }, | |
}), | |
PermissionsModule, | |
], | |
); | |
authService = module.get<AuthService>(AuthService); | |
const fixturesService = module.get<FixturesService>(FixturesService); | |
await fixturesService.run(); | |
}); | |
When( | |
'the user is login in with valid credentials {string} and {string}', | |
(email: string, password: string) => { | |
return authService.challenge({ email, password }).then((user) => { | |
if (user) { | |
return 'success'; | |
} | |
}); | |
}, | |
); | |
Then('the user should have a valid uuid token', async () => { | |
const user = await authService.challenge({ | |
email: '[email protected]', | |
password: 'test1234', | |
}); | |
const token = authService.generateToken(user); | |
if (token) { | |
return 'success'; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment