-
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.
* separation of concerns, add many tests * report coverage? * use correct env path in e2e test * spelling * correct dir * enable gh actions reporter * update reporter per docs * more dep prs
- Loading branch information
Showing
30 changed files
with
679 additions
and
214 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ lerna-debug.log* | |
# Tests | ||
/coverage | ||
/.nyc_output | ||
/coverage-e2e | ||
|
||
# IDEs and editors | ||
/.idea | ||
|
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
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 |
---|---|---|
|
@@ -3,13 +3,18 @@ import { AuthController } from './auth.controller'; | |
import { ConfigModule } from '@nestjs/config'; | ||
import { AuthService } from './auth.service'; | ||
import { JwtModule } from '@nestjs/jwt'; | ||
import { UsersService } from '@core/users/users.service'; | ||
import { PrismaService } from 'nestjs-prisma'; | ||
import { prismaMock } from '../../prisma/singleton'; | ||
import { I18nModule } from 'nestjs-i18n'; | ||
import i18n_opts from '@core/config/i18n'; | ||
import opts from '@core/config/app'; | ||
import { CredentialsService } from '@core/credentials/credentials.service'; | ||
import { | ||
CredentialsService, | ||
CredentialWithUserPii, | ||
} from '@core/credentials/credentials.service'; | ||
import { SessionService } from '@core/session/session.service'; | ||
import { addDays } from 'date-fns'; | ||
import { mockRequest } from '../../test/utils'; | ||
|
||
describe('AuthController', () => { | ||
let module: TestingModule; | ||
|
@@ -27,7 +32,7 @@ describe('AuthController', () => { | |
], | ||
providers: [ | ||
AuthService, | ||
UsersService, | ||
SessionService, | ||
CredentialsService, | ||
{ provide: PrismaService, useValue: prismaMock }, | ||
], | ||
|
@@ -43,4 +48,103 @@ describe('AuthController', () => { | |
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
|
||
describe('avatar', () => { | ||
it('should return an avatar if a session is provided', async () => { | ||
const result = await controller.avatar({ | ||
id: '1', | ||
created_at: new Date(), | ||
updated_at: new Date(), | ||
user_id: '1', | ||
user: { | ||
id: '1', | ||
created_at: new Date(), | ||
updated_at: new Date(), | ||
status: 'verified', | ||
pii: [ | ||
{ | ||
id: '1', | ||
created_at: new Date(), | ||
updated_at: new Date(), | ||
user_id: '1', | ||
type: 'email', | ||
value: '[email protected]', | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
expect(result).toMatch(/<a/); | ||
expect(result).toMatch(/hx-get="\/profile" hx-target="#main"/); | ||
expect(result).toMatch(/<div>me@email.com<\/div>/); | ||
}); | ||
it('should return auth links if no session is provided', async () => { | ||
const result = await controller.avatar(); | ||
expect(result).toMatch(/<nav id="auth-nav"/); | ||
expect(result).toMatch(/hx-get="\/auth\/sign-in" hx-target="#main"/); | ||
expect(result).toMatch(/hx-get="\/auth\/register" hx-target="#main"/); | ||
}); | ||
}); | ||
|
||
describe('signIn', () => { | ||
const email = '[email protected]'; | ||
const password = 'password'; | ||
const credential: CredentialWithUserPii = { | ||
id: '1', | ||
created_at: new Date(), | ||
updated_at: new Date(), | ||
user_id: '1', | ||
external_id: email, | ||
expires_at: addDays(new Date(), 1), | ||
refresh_token: null, | ||
type: 'password', | ||
value: 'value', | ||
user: { | ||
id: '1', | ||
created_at: new Date(), | ||
updated_at: new Date(), | ||
status: 'verified', | ||
pii: [ | ||
{ | ||
id: '1', | ||
created_at: new Date(), | ||
updated_at: new Date(), | ||
user_id: '1', | ||
type: 'email', | ||
value: email, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
beforeEach(() => { | ||
prismaMock.credential.findUniqueOrThrow.mockResolvedValue(credential); | ||
}); | ||
|
||
it('should return a sign in form', async () => { | ||
const result = await controller.signIn(); | ||
expect(result).toMatch(/<main id="main"/); | ||
expect(result).toMatch( | ||
/<form id="sign-in-form" hx-post="\/auth\/sign-in" hx-trigger="submit" hx-swap="none"/, | ||
); | ||
expect(result).toMatch(/<input type="email"/); | ||
expect(result).toMatch( | ||
/hx-target="#email-input" required placeholder="Enter your email" title="Email"/, | ||
); | ||
expect(result).toMatch(/<input type="password"/); | ||
expect(result).toMatch( | ||
/hx-target="#password-input" required placeholder="Enter your password" title="Password"/, | ||
); | ||
expect(result).toMatch(/<button type="submit"/); | ||
}); | ||
|
||
it('should return the credential if the user exists and password is correct', async () => { | ||
mockRequest.user = credential; | ||
const result = await controller.signInPost( | ||
{ email, password }, | ||
mockRequest, | ||
); | ||
expect(result).toEqual(credential); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.