-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add backdoor endpoint for test code
- Loading branch information
Showing
7 changed files
with
92 additions
and
53 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { UserEntity } from 'api/@types/user'; | ||
import { userMethod } from 'domain/user/model/userMethod'; | ||
import { userCommand } from 'domain/user/repository/userCommand'; | ||
import { genCredentials } from 'domain/user/service/genCredentials'; | ||
import { genTokens } from 'domain/user/service/genTokens'; | ||
import { userPoolQuery } from 'domain/userPool/repository/userPoolQuery'; | ||
import { DEFAULT_USER_POOL_CLIENT_ID, DEFAULT_USER_POOL_ID } from 'service/envValues'; | ||
import { prismaClient } from 'service/prismaClient'; | ||
import { genJwks } from 'service/privateKey'; | ||
import { defineController } from './$relay'; | ||
|
||
// サインアップフローを省略してテストを書くためのエンドポイント | ||
// 200行まではcontrollerにべた書きで良い | ||
export default defineController(() => ({ | ||
post: async ({ body }) => { | ||
const { salt, verifier } = genCredentials({ | ||
poolId: DEFAULT_USER_POOL_ID, | ||
username: body.username, | ||
password: body.password, | ||
}); | ||
const user: UserEntity = { | ||
...userMethod.createUser({ | ||
name: body.username, | ||
email: body.email, | ||
salt, | ||
verifier, | ||
userPoolId: DEFAULT_USER_POOL_ID, | ||
}), | ||
verified: true, | ||
}; | ||
|
||
await userCommand.save(prismaClient, user); | ||
|
||
const pool = await userPoolQuery.findById(prismaClient, DEFAULT_USER_POOL_ID); | ||
const jwks = await genJwks(pool.privateKey); | ||
const tokens = genTokens({ | ||
privateKey: pool.privateKey, | ||
userPoolClientId: DEFAULT_USER_POOL_CLIENT_ID, | ||
jwks, | ||
user, | ||
}); | ||
|
||
return { | ||
status: 200, | ||
body: { ...tokens, ExpiresIn: 3600, RefreshToken: user.refreshToken, TokenType: 'Bearer' }, | ||
}; | ||
}, | ||
})); |
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,13 @@ | ||
import type { RespondToAuthChallengeTarget } from 'api/@types/auth'; | ||
import type { DefineMethods } from 'aspida'; | ||
|
||
export type Methods = DefineMethods<{ | ||
post: { | ||
reqBody: { | ||
username: string; | ||
email: string; | ||
password: string; | ||
}; | ||
resBody: RespondToAuthChallengeTarget['resBody']['AuthenticationResult']; | ||
}; | ||
}>; |
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 @@ | ||
import { prismaClient } from 'service/prismaClient'; | ||
import { defineController } from './$relay'; | ||
|
||
// サインアップフローを省略してテストを書くためのエンドポイント | ||
// 200行まではcontrollerにべた書きで良い | ||
export default defineController(() => ({ | ||
delete: async ({ user }) => { | ||
await prismaClient.user.delete({ where: { id: user.id } }); | ||
|
||
return { status: 204 }; | ||
}, | ||
})); |
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,5 @@ | ||
import type { DefineMethods } from 'aspida'; | ||
|
||
export type Methods = DefineMethods<{ | ||
delete: { status: 204 }; | ||
}>; |
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