Skip to content

Commit

Permalink
Add tests for services error handlers (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
byn9826 authored Aug 29, 2024
1 parent f6910f8 commit ff13e59
Show file tree
Hide file tree
Showing 14 changed files with 1,164 additions and 77 deletions.
2 changes: 1 addition & 1 deletion server/src/configs/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export enum TableName {
export enum BaseKVKey {
JwtPublicSecret = 'jwtPublicSecret',
JwtPrivateSecret = 'jwtPrivateSecret',
sessionSecret = 'sessionSecret',
SessionSecret = 'sessionSecret',
RefreshToken = 'RT',
AuthCode = 'AC',
EmailMfaCode = 'EMC',
Expand Down
50 changes: 48 additions & 2 deletions server/src/routes/__tests__/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const createNewApp = async (token?: string) => await app.request(
name: 'test name',
type: 'spa',
scopes: ['profile', 'openid'],
redirectUris: ['http://localhost:4200', 'http://localhost:4300'],
redirectUris: ['http://LOCALHOST:4200', 'http://localhost:4300/'],
}),
headers: token === '' ? undefined : { Authorization: `Bearer ${token ?? await getS2sToken(db)}` },
},
Expand Down Expand Up @@ -269,7 +269,53 @@ describe(
await createNewApp()
const updateObj = {
name: 'test name 1',
redirectUris: ['http://localhost:5200', 'http://google.com'],
redirectUris: ['http://LOCALHOST:5200/', ' http://google.com '],
scopes: ['openid', 'offline_access'],
}
const res = await app.request(
`${BaseRoute}/3`,
{
method: 'PUT',
body: JSON.stringify(updateObj),
headers: { Authorization: `Bearer ${await getS2sToken(db)}` },
},
mock(db),
)
const json = await res.json()

expect(json).toStrictEqual({
app: {
...newApp,
...updateObj,
redirectUris: ['http://localhost:5200', 'http://google.com'],
},
})
},
)

test(
'should throw error if can not find app',
async () => {
await createNewApp()
const res = await app.request(
`${BaseRoute}/4`,
{
method: 'PUT',
body: JSON.stringify({ name: 'test name 1' }),
headers: { Authorization: `Bearer ${await getS2sToken(db)}` },
},
mock(db),
)
expect(res.status).toBe(404)
},
)

test(
'should update without affect redirect uris',
async () => {
await createNewApp()
const updateObj = {
name: 'test name 1',
scopes: ['openid', 'offline_access'],
}
const res = await app.request(
Expand Down
Loading

0 comments on commit ff13e59

Please sign in to comment.