forked from ustaxcourt/ef-cms
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
10007: Remove mockCognito, lean on localCognito exclusively.
- Loading branch information
Zachary Rogers
committed
Dec 6, 2023
1 parent
b6314d8
commit 05472f6
Showing
12 changed files
with
128 additions
and
168 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 |
---|---|---|
|
@@ -69,4 +69,5 @@ bulk-import-log.txt | |
metadata.json | ||
metadata-public.json | ||
stats.html | ||
other/ | ||
other/ | ||
.cognito/db/ |
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
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { CognitoIdentityServiceProvider } from 'aws-sdk'; | ||
import { cognitoLocalWrapper } from '@web-api/cognitoLocalWrapper'; | ||
|
||
let cognitoClientCache: CognitoIdentityServiceProvider; | ||
|
||
export function getCognito() { | ||
if (!cognitoClientCache) { | ||
cognitoClientCache = new CognitoIdentityServiceProvider({ | ||
httpOptions: { | ||
connectTimeout: 3000, | ||
timeout: 5000, | ||
}, | ||
maxRetries: 3, | ||
region: 'us-east-1', | ||
}); | ||
} | ||
return cognitoClientCache; | ||
} | ||
|
||
export function getMockCognito() { | ||
if (!cognitoClientCache) { | ||
cognitoClientCache = { | ||
adminCreateUser: () => ({ | ||
promise: () => ({ | ||
User: { | ||
Username: uuidv4(), | ||
}, | ||
}), | ||
}), | ||
adminDisableUser: () => ({ | ||
promise: () => {}, | ||
}), | ||
adminGetUser: ({ Username }) => ({ | ||
promise: async () => { | ||
// TODO: this scan might become REALLY slow while doing a full integration | ||
// test run. | ||
const items = await scan({ | ||
applicationContext: { | ||
environment, | ||
getDocumentClient, | ||
}, | ||
}); | ||
const users = items.filter( | ||
({ pk, sk }) => pk.startsWith('user|') && sk.startsWith('user|'), | ||
); | ||
const foundUser = users.find(({ email }) => email === Username); | ||
if (foundUser) { | ||
return { | ||
UserAttributes: [], | ||
Username: foundUser.userId, | ||
}; | ||
} else { | ||
const error = new Error(); | ||
error.code = 'UserNotFoundException'; | ||
throw error; | ||
} | ||
}, | ||
}), | ||
adminUpdateUserAttributes: () => ({ | ||
promise: () => {}, | ||
}), | ||
listUsers: () => ({ | ||
promise: () => { | ||
throw new Error( | ||
'Please use cognito locally by running npm run start:api:cognito-local', | ||
); | ||
}, | ||
}), | ||
}; | ||
} | ||
|
||
return cognitoClientCache; | ||
} | ||
|
||
export function getLocalCognito() { | ||
if (!cognitoClientCache) { | ||
cognitoClientCache = cognitoLocalWrapper( | ||
new CognitoIdentityServiceProvider({ | ||
endpoint: 'http://localhost:9229/', | ||
httpOptions: { | ||
connectTimeout: 3000, | ||
timeout: 5000, | ||
}, | ||
maxRetries: 3, | ||
region: 'local', | ||
}), | ||
); | ||
} | ||
return cognitoClientCache; | ||
} |
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 |
---|---|---|
|
@@ -318,43 +318,6 @@ describe('createOrUpdatePractitionerUser', () => { | |
}); | ||
}); | ||
|
||
it('should call adminCreateUser with the correct params when USE_COGNITO_LOCAL is true', async () => { | ||
process.env.USE_COGNITO_LOCAL = 'true'; | ||
process.env.USER_POOL_ID = 'localUserPoolId'; | ||
|
||
// setupNonExistingUserMock(); | ||
|
||
await createOrUpdatePractitionerUser({ | ||
applicationContext, | ||
user: privatePractitionerUser as any, | ||
}); | ||
|
||
expect( | ||
applicationContext.getCognito().adminCreateUser, | ||
).toHaveBeenCalledWith({ | ||
UserAttributes: [ | ||
{ | ||
Name: 'email_verified', | ||
Value: 'True', | ||
}, | ||
{ | ||
Name: 'email', | ||
Value: '[email protected]', | ||
}, | ||
{ | ||
Name: 'custom:role', | ||
Value: 'privatePractitioner', | ||
}, | ||
{ | ||
Name: 'name', | ||
Value: 'Test Private Practitioner', | ||
}, | ||
], | ||
UserPoolId: 'localUserPoolId', | ||
Username: '[email protected]', | ||
}); | ||
}); | ||
|
||
describe('createUserRecords', () => { | ||
it('attempts to persist a private practitioner user with name and barNumber mapping records', async () => { | ||
await createUserRecords({ | ||
|
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
Oops, something went wrong.