Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(DTFS2-6892): update tfm ui to save token #4052

Merged
merged 180 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
180 commits
Select commit Hold shift + click to select a range
6f01382
feat(dtfs2-6892): add api to upsert user
AlexBramhill Nov 25, 2024
70c1db3
feat(dtfs2-6892): add handle redirect to entra id service
AlexBramhill Nov 25, 2024
4dfd7dd
feat(dtfs2-6892): add user parital login data error
AlexBramhill Nov 27, 2024
51e6a20
Revert "feat(dtfs2-6892): add api to upsert user"
AlexBramhill Nov 27, 2024
eae68f8
Revert "feat(dtfs2-6892): add handle redirect to entra id service"
AlexBramhill Nov 27, 2024
9300c66
feat(dtfs2-6892): add login service
AlexBramhill Nov 27, 2024
d954593
feat(dtfs2-6892): add login service
AlexBramhill Nov 27, 2024
35fc108
feat(dtfs2-6892): add login service
AlexBramhill Nov 27, 2024
f973209
feat(dtfs2-6892): move entra to tfm api
AlexBramhill Nov 27, 2024
019ef20
feat(dtfs2-6892): move entra to tfm api
AlexBramhill Nov 27, 2024
9df20ed
feat(dtfs2-6892): move entra to tfm api
AlexBramhill Nov 27, 2024
6aa48cc
feat(dtfs2-6892): move entra to tfm api
AlexBramhill Nov 29, 2024
c036ea2
feat(dtfs2-6892): move entra to tfm api
AlexBramhill Nov 29, 2024
05ff7e4
Merge branch 'main' into feat/DTFS2-6892/add-frontend-upsert-user-fun…
AlexBramhill Nov 29, 2024
d5d1bb4
feat(dtfs2-6892): add object id schema for tfm sso
AlexBramhill Dec 3, 2024
fb5a89c
feat(dtfs2-6892): add tfm session user commonisation to dtfs-central-api
AlexBramhill Dec 3, 2024
ca22017
feat(dtfs2-6892): add tfm session user commonisation to dtfs-central-api
AlexBramhill Dec 3, 2024
e2eecd1
feat(dtfs2-6892): add tfm session user commonisation to tfm-api
AlexBramhill Dec 3, 2024
9a0b176
feat(dtfs2-6892): fix eslint errors
AlexBramhill Dec 3, 2024
6668392
feat(dtfs2-6892): update tfm ui
AlexBramhill Dec 3, 2024
eb080b3
feat(dtfs2-6892): fix create tfm user request
AlexBramhill Dec 3, 2024
d3da1ad
feat(dtfs2-6892): update schema tests
AlexBramhill Dec 4, 2024
bdf5a87
feat(dtfs2-6892): update entra user id tests
AlexBramhill Dec 4, 2024
2e412f4
feat(dtfs2-6892): update entra user id auth result tests
AlexBramhill Dec 4, 2024
b74aeab
feat(dtfs2-6892): fix tests
AlexBramhill Dec 4, 2024
a2bf551
feat(dtfs2-6892): fix tests
AlexBramhill Dec 4, 2024
f8c998d
feat(dtfs2-6892): fix tests
AlexBramhill Dec 4, 2024
74c8cac
feat(dtfs2-6892): add unix timestamp tests
AlexBramhill Dec 4, 2024
836239c
feat(dtfs2-6892): tidy, add comments
AlexBramhill Dec 4, 2024
7c39850
feat(dtfs2-6892): rename field to param
AlexBramhill Dec 4, 2024
a5d8e78
feat(dtfs2-6892): fix test
AlexBramhill Dec 4, 2024
010cb9a
feat(dtfs2-6892): add missing type for get auth code
AlexBramhill Nov 29, 2024
7b4def0
feat(dtfs2-6892): add handle sso redirect form types
AlexBramhill Nov 29, 2024
749e267
feat(dtfs2-6892): add handle sso redirect form types
AlexBramhill Nov 29, 2024
1ea6af6
feat(dtfs2-6892): update user session to be split between fully authe…
AlexBramhill Nov 29, 2024
cdb3e5f
feat(dtfs2-6892): update tfm ui
AlexBramhill Nov 29, 2024
e48b42d
feat(dtfs2-6892): add lost tfm api file changes
AlexBramhill Dec 3, 2024
cf47e66
feat(dtfs2-6892): add lost files
AlexBramhill Dec 3, 2024
6d2e06d
feat(dtfs2-6892): success redirect to be optional
AlexBramhill Dec 3, 2024
4afebe8
feat(dtfs2-6892): update sso controller
AlexBramhill Dec 4, 2024
1225d7e
feat(dtfs2-6892): move api test file into separate tests
AlexBramhill Dec 5, 2024
3681433
feat(dtfs2-6892): update eslint to allow for _getJsonData
AlexBramhill Dec 6, 2024
677f531
feat(dtfs2-6892): add sso controller get auth code url tests
AlexBramhill Dec 6, 2024
c1e97ea
feat(dtfs2-6892): add builder
AlexBramhill Dec 6, 2024
e785461
feat(dtfs2-6892): update test api error constructor
AlexBramhill Dec 6, 2024
48b4125
feat(dtfs2-6892): add with api error tests helper
AlexBramhill Dec 6, 2024
e31235d
feat(dtfs2-6892): remove unused upsert functions
AlexBramhill Dec 6, 2024
eb16e75
feat(dtfs2-6892): update error handling and tests for get auth code
AlexBramhill Dec 6, 2024
a9280e9
feat(dtfs2-6892): update user service to not be static
AlexBramhill Dec 6, 2024
bf6056c
feat(dtfs2-6892): add sso controller tests for handle sso redirect form
AlexBramhill Dec 9, 2024
fda5a2d
Merge branch 'main' into feat/DTFS2-6892/add-frontend-upsert-user-fun…
AlexBramhill Dec 9, 2024
0a85711
Merge branch 'feat/DTFS2-6892/add-frontend-upsert-user-functionality'…
AlexBramhill Dec 9, 2024
a590fa5
Merge branch 'feat/DTFS2-6892/commonise-tfm-session-user' into feat/D…
AlexBramhill Dec 9, 2024
cca4a64
Merge branch 'feat/DTFS2-6892/add-schema-tests-for-commonised-tfm-use…
AlexBramhill Dec 9, 2024
4513794
feat(dtfs2-6892): add tests
AlexBramhill Dec 9, 2024
466f33a
feat(dtfs2-6892): remove tfm ui changes
AlexBramhill Dec 9, 2024
335708a
feat(dtfs2-6892): remove tfm ui changes
AlexBramhill Dec 9, 2024
e230163
feat(dtfs2-6892): update mock builder
AlexBramhill Dec 11, 2024
2151f8b
Revert "feat(dtfs2-6892): remove tfm ui changes"
AlexBramhill Dec 9, 2024
a137cff
Revert "feat(dtfs2-6892): remove tfm ui changes"
AlexBramhill Dec 9, 2024
1bdd738
feat(dtfs2-6892): add user session service
AlexBramhill Dec 11, 2024
5bac4d5
feat(dtfs2-6892): update user session types
AlexBramhill Dec 11, 2024
3a3244a
feat(dtfs2-6892): add user sesion mock builder and tests
AlexBramhill Dec 11, 2024
dee0e9a
feat(dtfs2-6892): update mock builders
AlexBramhill Dec 11, 2024
20941f4
feat(dtfs2-6892): split express session tests
AlexBramhill Dec 11, 2024
449e60d
feat(dtfs2-6892): add express session tests
AlexBramhill Dec 11, 2024
527b543
feat(dtfs2-6892): add express session tests
AlexBramhill Dec 11, 2024
33a1dd2
feat(dtfs2-6892): update user session service import
AlexBramhill Dec 11, 2024
a71a3bf
feat(dtfs2-6892): update user session service tests
AlexBramhill Dec 11, 2024
9ef9ed3
feat(dtfs2-6892): update login controller to handle errors
AlexBramhill Dec 11, 2024
f70d97f
feat(dtfs2-6892): add login service handle sso redirect form tests
AlexBramhill Dec 11, 2024
824411e
feat(dtfs2-6892): add login controller tests
AlexBramhill Dec 12, 2024
6f04dad
feat(DTFS2-6892): update mock builder to require complete defaults, a…
AlexBramhill Jan 2, 2025
15ecd10
feat(DTFS2-6892): add object id schema for tfm sso (#4027)
AlexBramhill Jan 2, 2025
46c85f5
feat(DTFS2-6892): refactored code
Jan 3, 2025
1bd2233
Merge branch 'main' into feat/DTFS2-6892/add-frontend-upsert-user-fun…
AlexBramhill Jan 3, 2025
351221d
Merge branch 'feat/DTFS2-6892/add-frontend-upsert-user-functionality'…
AlexBramhill Jan 3, 2025
f49019a
fix(dtfs2-7647): update tfm session user imports
AlexBramhill Jan 3, 2025
42d9080
Merge branch 'feat/DTFS2-6892/commonise-tfm-session-user' into feat/D…
AlexBramhill Jan 6, 2025
6543278
Revert "feat(DTFS2-6892): update mock builder to require complete def…
AlexBramhill Jan 6, 2025
4fe1900
Merge branch 'main' into feat/DTFS2-6892/add-frontend-upsert-user-fun…
AlexBramhill Jan 6, 2025
0d524c6
Merge branch 'feat/DTFS2-6892/add-frontend-upsert-user-functionality'…
AlexBramhill Jan 6, 2025
9aa8593
Merge branch 'feat/DTFS2-6892/commonise-tfm-session-user' into feat/D…
AlexBramhill Jan 6, 2025
71e6a2b
Merge branch 'feat/DTFS2-6892/add-schema-tests-for-commonised-tfm-use…
AlexBramhill Jan 6, 2025
2f26ad3
Merge branch 'feat/DTFS2-6892/add-token-issuance' into feat/DTFS2-689…
AlexBramhill Jan 6, 2025
d459281
feat(dtfs2-6892): add readme
AlexBramhill Jan 6, 2025
8fe75fd
feat(dtfs2-6892): add readme
AlexBramhill Jan 6, 2025
4744df8
feat(dtfs2-6892): update tests
AlexBramhill Jan 7, 2025
cd59c23
feat(dtfs2-6892): review comments
AlexBramhill Jan 7, 2025
f1d97f2
feat(dtfs2-6892): review comments
AlexBramhill Jan 7, 2025
9f60efa
feat(dtfs2-6892): review comments
AlexBramhill Jan 7, 2025
d6929c3
feat(dtfs2-6892): review comments
AlexBramhill Jan 7, 2025
3eb8aef
feat(dtfs2-6892): fix ts error
AlexBramhill Jan 7, 2025
9ebfdac
feat(dtfs2-6892): update to review comments
AlexBramhill Jan 14, 2025
ec175ad
feat(dtfs2-7693): update to review comments
AlexBramhill Jan 14, 2025
b827c69
feat(dtfs2-7693): update to review comments
AlexBramhill Jan 14, 2025
dd1dedf
feat(dtfs2-6892): update HandleSsoRedirectFormResponse to use schema,…
AlexBramhill Jan 15, 2025
edbe348
Revert "feat(DTFS2-6892): refactored code"
AlexBramhill Jan 15, 2025
3e80688
feat(dtfs2-6892): clarify how zod union works
AlexBramhill Jan 22, 2025
6c08a10
feat(dtfs2-6892): update to review comments
AlexBramhill Jan 22, 2025
4829ecc
feat(dtfs2-6892): add sso controller test
AlexBramhill Jan 23, 2025
3f94a37
feat(dtfs2-6892): update controller reroute, add tests
AlexBramhill Jan 23, 2025
f2e2f5e
feat(dtfs2-6892): uninstall msal node from tfm ui
AlexBramhill Jan 23, 2025
bbc537f
Merge branch 'main' into feat/DTFS2-6892/add-frontend-upsert-user-fun…
AlexBramhill Jan 23, 2025
f8052c8
Merge branch 'feat/DTFS2-6892/add-frontend-upsert-user-functionality'…
AlexBramhill Jan 23, 2025
ec2e327
feat(dtfs2-6892): remove todo
AlexBramhill Jan 23, 2025
a473a42
Merge branch 'feat/DTFS2-6892/commonise-tfm-session-user' into feat/D…
AlexBramhill Jan 23, 2025
a78e8a8
Merge branch 'feat/DTFS2-6892/add-schema-tests-for-commonised-tfm-use…
AlexBramhill Jan 23, 2025
705d0b6
feat(dtfs2-6892): update mock builder to use test helper
AlexBramhill Jan 24, 2025
af8e047
Merge branch 'feat/DTFS2-6892/add-token-issuance' into feat/DTFS2-689…
AlexBramhill Jan 24, 2025
ae9107e
feat(dtfs2-6892): review comments
AlexBramhill Jan 24, 2025
d4abcad
feat(dtfs2-6892): review comments
AlexBramhill Jan 28, 2025
ef3d702
Merge branch 'main' into feat/DTFS2-6892/add-frontend-upsert-user-fun…
AlexBramhill Jan 31, 2025
b1b1e5f
Merge branch 'feat/DTFS2-6892/add-frontend-upsert-user-functionality'…
AlexBramhill Jan 31, 2025
6ff0fbc
Merge branch 'feat/DTFS2-6892/commonise-tfm-session-user' into feat/D…
AlexBramhill Jan 31, 2025
93b5586
Merge branch 'feat/DTFS2-6892/add-schema-tests-for-commonised-tfm-use…
AlexBramhill Jan 31, 2025
a447143
Merge branch 'feat/DTFS2-6892/add-token-issuance' into feat/DTFS2-689…
AlexBramhill Jan 31, 2025
494366e
feat(dtfs2-6892): fix lint issue
AlexBramhill Feb 3, 2025
5115a86
Merge branch 'main' into feat/DTFS2-6892/add-frontend-upsert-user-fun…
AlexBramhill Feb 4, 2025
b9ccfda
Merge branch 'feat/DTFS2-6892/add-frontend-upsert-user-functionality'…
AlexBramhill Feb 4, 2025
5f528b5
feat(dtfs2-6892): fix following rebase
AlexBramhill Feb 4, 2025
9e98f19
feat(dtfs2-6892): fix following rebase
AlexBramhill Feb 4, 2025
c3adb9d
Merge branch 'main' into feat/DTFS2-6892/add-frontend-upsert-user-fun…
AlexBramhill Feb 4, 2025
da638aa
Merge branch 'feat/DTFS2-6892/add-frontend-upsert-user-functionality'…
AlexBramhill Feb 4, 2025
33cc3a3
Merge branch 'feat/DTFS2-6892/commonise-tfm-session-user' into feat/D…
AlexBramhill Feb 4, 2025
038b04b
feat(dtfs2-6892): fix following rebase
AlexBramhill Feb 4, 2025
78a813d
feat(dtfs2-6892): fix following rebase
AlexBramhill Feb 4, 2025
2a1f587
Merge branch 'feat/DTFS2-6892/add-schema-tests-for-commonised-tfm-use…
AlexBramhill Feb 4, 2025
7e725ae
feat(dtfs2-6892): fix following rebase
AlexBramhill Feb 5, 2025
7d7a8a5
Merge branch 'main' into feat/DTFS2-6892/commonise-tfm-session-user
AlexBramhill Feb 5, 2025
341251f
Merge branch 'feat/DTFS2-6892/commonise-tfm-session-user' into feat/D…
AlexBramhill Feb 5, 2025
988cf25
Merge branch 'feat/DTFS2-6892/add-schema-tests-for-commonised-tfm-use…
AlexBramhill Feb 5, 2025
47ee83c
feat(dtfs2-6892): fix following rebase
AlexBramhill Feb 5, 2025
a247c7b
Merge branch 'feat/DTFS2-6892/add-token-issuance' into feat/DTFS2-689…
AlexBramhill Feb 5, 2025
47dcaa1
feat(dtfs2-6892): fix following rebase
AlexBramhill Feb 5, 2025
1da8335
feat(dtfs2-6892): fix following rebase
AlexBramhill Feb 5, 2025
8a9ca34
feat(dtfs2-6892): fix following rebase
AlexBramhill Feb 5, 2025
930f3f8
feat(dtfs2-6892): fix following rebase
AlexBramhill Feb 5, 2025
d889fb1
feat(dtfs2-6892): review comments
AlexBramhill Feb 5, 2025
60df464
feat(dtfs2-6892): review comments
AlexBramhill Feb 5, 2025
c016d28
Merge branch 'feat/DTFS2-6892/commonise-tfm-session-user' into feat/D…
AlexBramhill Feb 5, 2025
4ca17e3
Merge branch 'feat/DTFS2-6892/add-schema-tests-for-commonised-tfm-use…
AlexBramhill Feb 5, 2025
0923f89
Merge branch 'feat/DTFS2-6892/add-token-issuance' into feat/DTFS2-689…
AlexBramhill Feb 5, 2025
1ef4091
feat(dtfs2-6892): review comments
AlexBramhill Feb 6, 2025
897e457
Merge branch 'main' into feat/DTFS2-6892/commonise-tfm-session-user
AlexBramhill Feb 7, 2025
8589fc2
feat(dtfs2-6892): review comments
AlexBramhill Feb 10, 2025
0e0fffa
feat(dtfs2-6892): review comments
AlexBramhill Feb 10, 2025
12c1215
feat(dtfs2-6892): review comments
AlexBramhill Feb 10, 2025
8d33fb8
Merge branch 'feat/DTFS2-6892/commonise-tfm-session-user' into feat/D…
AlexBramhill Feb 10, 2025
4cf11c9
Merge branch 'main' into feat/DTFS2-6892/add-schema-tests-for-commoni…
AlexBramhill Feb 10, 2025
9d2856c
feat(dtfs2-6892): review comments
AlexBramhill Feb 10, 2025
40d7383
Merge branch 'main' into feat/DTFS2-6892/add-schema-tests-for-commoni…
AlexBramhill Feb 12, 2025
5c40efe
Merge branch 'feat/DTFS2-6892/add-schema-tests-for-commonised-tfm-use…
AlexBramhill Feb 12, 2025
08d6ce1
feat(dtfs2-6892): review comments
AlexBramhill Feb 12, 2025
694c80b
feat(dtfs2-6892): fix issue due to unit test and e2e tests running on…
AlexBramhill Feb 12, 2025
8552633
feat(dtfs2-6892): fix issue due to unit test and e2e tests running on…
AlexBramhill Feb 12, 2025
5f3b106
feat(dtfs2-6892): fix issue due to unit test and e2e tests running on…
AlexBramhill Feb 12, 2025
7fdc71e
feat(dtfs2-6892): fix issue due to unit test and e2e tests running on…
AlexBramhill Feb 12, 2025
f09d87e
feat(dtfs2-6892): fix issue due to unit test and e2e tests running on…
AlexBramhill Feb 13, 2025
8621e1b
Merge branch 'feat/DTFS2-6892/add-schema-tests-for-commonised-tfm-use…
AlexBramhill Feb 13, 2025
41a5dc7
Merge branch 'feat/DTFS2-6892/add-schema-tests-for-commonised-tfm-use…
AlexBramhill Feb 13, 2025
4f3d681
Merge branch 'feat/DTFS2-6892/add-token-issuance' into feat/DTFS2-689…
AlexBramhill Feb 13, 2025
5e8d737
feat(dtfs2-6892): review comments
AlexBramhill Feb 13, 2025
ffea733
Merge branch 'main' into feat/DTFS2-6892/add-token-issuance
AlexBramhill Feb 13, 2025
a73928a
Merge branch 'main' into feat/DTFS2-6892/add-token-issuance
AlexBramhill Feb 13, 2025
fb825f5
Merge branch 'feat/DTFS2-6892/add-token-issuance' into feat/DTFS2-689…
AlexBramhill Feb 13, 2025
719970d
feat(dtfs2-6892): review comments
AlexBramhill Feb 13, 2025
e331e12
feat(dtfs2-6892): remove need for backend separate schema tests
AlexBramhill Feb 13, 2025
6874d39
feat(dtfs2-6892): remove need for backend separate schema tests
AlexBramhill Feb 13, 2025
36cc84c
Merge branch 'feat/DTFS2-6892/add-token-issuance' into feat/DTFS2-689…
AlexBramhill Feb 13, 2025
0c4b950
Merge branch 'main' into feat/DTFS2-6892/update-tfm-ui-to-issue-token
AlexBramhill Feb 14, 2025
c0efbb6
feat(dtfs2-6892): review comments
AlexBramhill Feb 14, 2025
264eee3
feat(dtfs2-6892): add msal to tfm ui
AlexBramhill Feb 14, 2025
e509575
feat(dtfs2-6892): review comments
AlexBramhill Feb 14, 2025
c0a9b7e
Revert "feat(dtfs2-6892): add msal to tfm ui"
AlexBramhill Feb 14, 2025
eceae23
feat(dtfs2-6892): add msal to tfm ui
AlexBramhill Feb 14, 2025
c2a2310
Revert "feat(dtfs2-6892): add msal to tfm ui"
AlexBramhill Feb 14, 2025
64c2f41
feat(dtfs2-6892): add msal to tfm ui
AlexBramhill Feb 14, 2025
b013e6d
Revert "feat(dtfs2-6892): add msal to tfm ui"
AlexBramhill Feb 14, 2025
d2896ea
feat(dtfs2-6892): add msal to tfm ui
AlexBramhill Feb 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { aValidTfmSessionUser, withSchemaValidationTests } from '../../test-helpers/schemas';
import { HANDLE_SSO_REDIRECT_FORM_RESPONSE_SCHEMA } from './handle-sso-redirect-form-response.schema';

describe('HANDLE_SSO_REDIRECT_FORM_RESPONSE_SCHEMA', () => {
withSchemaValidationTests({
schema: HANDLE_SSO_REDIRECT_FORM_RESPONSE_SCHEMA,
aValidPayload,
testCases: [
{
parameterPath: 'user',
type: 'TFM_SESSION_USER_SCHEMA',
options: {
overrideGetTestObjectWithUpdatedField: (newValue: unknown) => ({ ...aValidPayload(), user: newValue }),
},
},
{
parameterPath: 'token',
type: 'string',
},
{
parameterPath: 'expires',
type: 'string',
},
{
parameterPath: 'successRedirect',
type: 'string',
options: {
isOptional: true,
},
},
],
});

function aValidPayload() {
return { user: aValidTfmSessionUser(), token: 'a-token', expires: 'a-date', successRedirect: 'a-redirect' };
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { z } from 'zod';
import { TFM_SESSION_USER_SCHEMA } from './tfm-session-user.schema';

export const HANDLE_SSO_REDIRECT_FORM_RESPONSE_SCHEMA = z.object({
user: TFM_SESSION_USER_SCHEMA,
token: z.string(),
expires: z.string(),
successRedirect: z.string().optional(),
});
1 change: 1 addition & 0 deletions libs/common/src/schemas/tfm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from './upsert-tfm-user-request.schema';
export * from './tfm-team.schema';
export * from './tfm-user.schema';
export * from './tfm-session-user.schema';
export * from './handle-sso-redirect-form-response.schema';
10 changes: 10 additions & 0 deletions libs/common/src/schemas/tfm/tfm-session-user.schema.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { withTfmSessionUserSchemaTests } from '../../test-helpers/schemas';
import { TFM_SESSION_USER_SCHEMA } from './tfm-session-user.schema';

describe('TFM_SESSION_USER_SCHEMA', () => {
withTfmSessionUserSchemaTests({
schema: TFM_SESSION_USER_SCHEMA,
getTestObjectWithUpdatedParameter: (newValue: unknown) => newValue,
getUpdatedParameterFromParsedTestObject: (data) => data,
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ type Mocked<T> = {
};

/**
* Base class for class test data builders. Pass in default values for the class
* instance so that you can build an instance with those values and override
* them as needed.
* Base class for class test data and class builders.
*
* Pass in default values for the instance so that you can build an instance with
* those values and override them as needed.
*
* @example
* Overriding the defaults of a type:
* ```ts
* // Basic builder
* // user.mock.builder.ts
* // Basic builder for a type
* export class UserMockBuilder extends BaseMockBuilder<User> {
* constructor() {
* super({
Expand All @@ -24,52 +27,61 @@ type Mocked<T> = {
* })
* }
* }
*
* // a-test-file.test.ts
* // Usage in a test where we just need a valid class instance
* const user = new UserMockBuilder().build()
*
* // another-test-file.test.ts
* // Usage in a test where a field needs to have a specific value
* const user = new UserMockBuilder()
* .with({ email: 'new.email@ukef.gov.uk' })
* .build()
* ```

*
* @example
* Overriding the defaults of a class:
* ```ts
* // With custom static factory methods to initialise the builder
* export class UserMockBuilder extends BaseMockBuilder<User> {
* constructor(defaultInstance?: User) {
* export class LoginServiceMockBuilder extends BaseMockBuilder<LoginService> {
* constructor() {
* super({
* defaultInstance: defaultInstance ?? {
* id: '72f9ca55-943a-401d-a04c-0a9e03ac7f18',
* name: 'Joe Bloggs',
* email: 'joe.bloggs@ukef.gov.uk',
* defaultInstance: {
* getAuthCodeUrl: jest.fn(async () => {
* return Promise.resolve({
* authCodeUrl: 'a-auth-code-url',
* authCodeUrlRequest: {} as AuthorizationCodeRequest,
* });
* }),
* },
* })
* }
*
* public static fromEntity(entity: UserEntity): UserMockBuilder {
* return new UserMockBuilder({
* id: entity.id,
* name: entity.name,
* email: entity.email,
* })
* });
* }
* }
* ```
*
* @example
* ```ts
* // Usage in a test where we just need a valid class instance
* const user = new UserMockBuilder().build()
* ```
*
* @example
*
* Keeping existing implimentations of a class:
* ```ts
* // Usage in a test where a field needs to have a specific value
* const user = new UserMockBuilder()
* .with({ email: 'new.email@ukef.gov.uk' })
* .build()
* export class UserServiceMockBuilder extends BaseMockBuilder<UserService> {
* constructor() {
* const userService = new UserService(); // This can be used as a way to inherit methods we do not wish to mock the implimentation for
* super({
* defaultInstance: {
* transformEntraIdUserToUpsertTfmUserRequest(entraIdUser: EntraIdUser): UpsertTfmUserRequest {
* return userService.transformEntraIdUserToUpsertTfmUserRequest(entraIdUser);
* },
* saveUserLoginInformation({ userId, sessionIdentifier, auditDetails }: saveUserLoginInformationParams): Promise<void> {
* return Promise.resolve();
* },
* },
* });
* }
* ```
*/
export abstract class BaseMockBuilder<TClass extends object> {
private readonly defaults: Partial<Mocked<TClass>>;
private readonly instance: Mocked<TClass> = {} as Mocked<TClass>;

protected constructor(config: { defaultInstance: Partial<Mocked<TClass>> }) {
this.defaults = config.defaultInstance;
protected constructor(config: { defaultInstance: Mocked<TClass> }) {
this.with(config.defaultInstance);
}

/**
Expand All @@ -90,10 +102,6 @@ export abstract class BaseMockBuilder<TClass extends object> {
return this;
}

public withDefaults(): BaseMockBuilder<TClass> {
return this.with(this.defaults);
}

/**
* Build the class instance after setting any fields
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { GetAuthCodeUrlResponse } from '../../types';
import { anAuthorisationCodeRequest } from './authorisation-code-request.mock';

export const aGetAuthCodeUrlResponse = (): GetAuthCodeUrlResponse => ({
authCodeUrl: 'a-auth-code-url',
authCodeUrlRequest: anAuthorisationCodeRequest(),
});
2 changes: 1 addition & 1 deletion libs/common/src/test-helpers/mock-data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export * from './upsert-tfm-user-request';
export * from './record-correction-mock';
export * from './entra-id-auth-code-redirect-response-body';
export * from './fee-record-correction-request-transient-form-data.entity.mock-builder';
export * from './get-auth-code-url-response';
export * from './get-auth-code-url-params';
export * from './fee-record-correction-transient-form-data.entity.mock-builder';
export * from './get-auth-code-url-response.mock';
export * from './fee-record-correction-request-review-response-body-mock';
export * from './record-correction-values';
export * from './record-correction-log-details.mock';
1 change: 1 addition & 0 deletions libs/common/src/test-helpers/schemas/schema-tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
* ie these schemas represent a whole object, not a single field
*/
export * from './with-entra-id-user-schema.tests';
export * from './with-tfm-session-user-schema.tests';
export * from './with-upsert-tfm-user-request.schema.tests';
export * from './with-audit-database-record-schema.tests';
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { ZodSchema } from 'zod';
import { ObjectId } from 'mongodb';
import { TEAM_IDS } from '../../../constants';
import { withSchemaValidationTests } from '../with-schema-validation.tests';
import { withDefaultOptionsTests } from '../primitive-types-tests';
import { WithSchemaTestParams } from '../types/with-schema-test.type';

export const withTfmSessionUserSchemaTests = <Schema extends ZodSchema>({
schema,
options = {},
getTestObjectWithUpdatedParameter,
getUpdatedParameterFromParsedTestObject,
}: WithSchemaTestParams<Schema>) => {
describe('with TFM_SESSION_USER_SCHEMA tests', () => {
withDefaultOptionsTests({
schema,
options,
getTestObjectWithUpdatedParameter,
getUpdatedParameterFromParsedTestObject,
});

withSchemaValidationTests({
schema,
aValidPayload,
testCases: [
{
parameterPath: '_id',
type: 'OBJECT_ID_STRING_SCHEMA',
options: {
overrideGetTestObjectWithUpdatedField: (newValue) => getTestObjectWithUpdatedParameter({ ...aValidPayload(), _id: newValue }),
},
},
{
parameterPath: 'username',
type: 'string',
options: {
overrideGetTestObjectWithUpdatedField: (newValue) => getTestObjectWithUpdatedParameter({ ...aValidPayload(), username: newValue }),
},
},
{
parameterPath: 'email',
type: 'string',
options: {
overrideGetTestObjectWithUpdatedField: (newValue) => getTestObjectWithUpdatedParameter({ ...aValidPayload(), email: newValue }),
},
},
{
parameterPath: 'timezone',
type: 'string',
options: {
overrideGetTestObjectWithUpdatedField: (newValue) => getTestObjectWithUpdatedParameter({ ...aValidPayload(), timezone: newValue }),
},
},
{
parameterPath: 'firstName',
type: 'string',
options: {
overrideGetTestObjectWithUpdatedField: (newValue) => getTestObjectWithUpdatedParameter({ ...aValidPayload(), firstName: newValue }),
},
},
{
parameterPath: 'lastName',
type: 'string',
options: {
overrideGetTestObjectWithUpdatedField: (newValue) => getTestObjectWithUpdatedParameter({ ...aValidPayload(), lastName: newValue }),
},
},
{
parameterPath: 'status',
type: 'string',
options: {
overrideGetTestObjectWithUpdatedField: (newValue) => getTestObjectWithUpdatedParameter({ ...aValidPayload(), status: newValue }),
},
},
{
parameterPath: 'lastLogin',
type: 'UNIX_TIMESTAMP_MILLISECONDS_SCHEMA',
options: {
isOptional: true,
overrideGetTestObjectWithUpdatedField: (newValue) => getTestObjectWithUpdatedParameter({ ...aValidPayload(), lastLogin: newValue }),
},
},
{
parameterPath: 'teams',
type: 'Array',
options: {
arrayTypeTestCase: {
type: 'TfmTeamSchema',
},
overrideGetTestObjectWithUpdatedField: (newValue) => getTestObjectWithUpdatedParameter({ ...aValidPayload(), teams: newValue }),
},
},
],
});

function aValidPayload() {
return aValidTfmSessionUser();
}
});
};

export function aValidTfmSessionUser() {
return {
_id: new ObjectId().toString(),
username: 'test-user',
email: 'test-user@ukexportfinance.gov.uk',
teams: [TEAM_IDS.PIM],
timezone: 'Europe/London',
firstName: 'FirstName',
lastName: 'LastName',
status: 'active',
lastLogin: 1234567890123,
};
}
3 changes: 2 additions & 1 deletion libs/common/src/test-helpers/schemas/test-cases/test-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export type TestCase =
| TestCaseWithType<'OBJECT_ID_SCHEMA'>
| TestCaseWithType<'OBJECT_ID_STRING_SCHEMA'>
| TestCaseWithType<'OBJECT_ID_OR_OBJECT_ID_STRING_SCHEMA'>
| TestCaseWithType<'AUDIT_DATABASE_RECORD_SCHEMA'>;
| TestCaseWithType<'AUDIT_DATABASE_RECORD_SCHEMA'>
| TestCaseWithType<'TFM_SESSION_USER_SCHEMA'>;
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import {
withObjectIdOrObjectIdStringSchemaTests,
} from '../custom-types-tests';
import { withStringTests, withNumberTests, withBooleanTests, withArrayTests } from '../primitive-types-tests';
import { withAuditDatabaseRecordSchemaTests, withEntraIdUserSchemaTests, withUpsertTfmUserRequestSchemaTests } from '../schema-tests';
import {
withAuditDatabaseRecordSchemaTests,
withEntraIdUserSchemaTests,
withTfmSessionUserSchemaTests,
withUpsertTfmUserRequestSchemaTests,
} from '../schema-tests';
import { withIsoDateTimeStampToDateSchemaTests } from '../transformation-tests';
import { WithTestsForTestCaseProps } from '../types/with-tests-for-test-case';

Expand Down Expand Up @@ -177,6 +182,15 @@ export const withTestsForTestcase = <Schema extends ZodSchema>(props: WithTestsF
});
break;

case 'TFM_SESSION_USER_SCHEMA':
withTfmSessionUserSchemaTests({
schema,
options,
getTestObjectWithUpdatedParameter,
getUpdatedParameterFromParsedTestObject,
});
break;

default:
throw Error(`There are no existing test cases for the type ${type}`);
}
Expand Down
10 changes: 3 additions & 7 deletions libs/common/src/types/tfm/handle-sso-redirect-form.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import { AuthorizationUrlRequest } from '@azure/msal-node';
import { Response } from 'express';
import z from 'zod';
import { EntraIdAuthCodeRedirectResponseBody } from './entra-id';
import { TfmSessionUser } from './tfm-session-user';
import { AuditDetails } from '../audit-details';
import { CustomExpressRequest } from '../express-custom-request';
import { ApiErrorResponseBody } from '../api-error-response-body';
import { HANDLE_SSO_REDIRECT_FORM_RESPONSE_SCHEMA } from '../../schemas/tfm/handle-sso-redirect-form-response.schema';

export type HandleSsoRedirectFormRequest = {
authCodeResponse: EntraIdAuthCodeRedirectResponseBody;
originalAuthCodeUrlRequest: AuthorizationUrlRequest;
auditDetails: AuditDetails<'system'>;
};

export type HandleSsoRedirectFormResponse = {
user: TfmSessionUser;
token: string;
expires: string;
successRedirect?: string;
};
export type HandleSsoRedirectFormResponse = z.infer<typeof HANDLE_SSO_REDIRECT_FORM_RESPONSE_SCHEMA>;

export type HandleSsoRedirectFormUiRequest = CustomExpressRequest<{ reqBody: EntraIdAuthCodeRedirectResponseBody }>;

Expand Down
Loading
Loading