This repository has been archived by the owner on May 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(personaIdentifier lock): Add lockedAt field to handle expired loc…
…ks on personaIdentifiers (LLC-1877) (#400)
- Loading branch information
1 parent
1d012e8
commit 90ad2a2
Showing
25 changed files
with
585 additions
and
85 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
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,11 @@ | ||
import BaseError from 'jscommons/dist/errors/BaseError'; | ||
import Identifier from '../models/Identifier'; | ||
|
||
export class ExpiredLock extends BaseError { | ||
constructor( | ||
public identifier: Identifier, | ||
public ignorePersonaId: boolean, | ||
) { | ||
super(); | ||
} | ||
} |
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
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
72 changes: 72 additions & 0 deletions
72
src/mongoModelsRepo/tests/createPersonaAndAddToIdentifier.test.ts
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,72 @@ | ||
import * as assert from 'assert'; | ||
import { | ||
MongoClient, | ||
} from 'mongodb'; | ||
|
||
import config from '../../config'; | ||
import repoFactory from '../../repoFactory'; | ||
import ServiceConfig from '../../service/Config'; | ||
import { TEST_IFI, TEST_ORGANISATION } from '../../tests/utils/values'; | ||
import createUpdateIdentifierPersona from '../createUpdateIdentifierPersona'; | ||
import creatIdentifier from '../utils/createIdentifier'; | ||
import { createPersonaAndAddToIdentifier } from '../utils/createPersonaAndAddToIdentifier'; | ||
|
||
describe('', async () => { | ||
|
||
let serviceConfig: ServiceConfig; // tslint:disable-line:no-let | ||
beforeEach(async () => { | ||
const repoFacade = repoFactory(); | ||
serviceConfig = {repo: repoFacade}; | ||
await serviceConfig.repo.clearRepo(); | ||
}); | ||
|
||
const generateMockDb = async () => { | ||
return (await MongoClient.connect( | ||
config.mongoModelsRepo.url, | ||
config.mongoModelsRepo.options, | ||
)).db(); | ||
}; | ||
|
||
it( | ||
'Should create a new persona and add toidentifier if identifier doens\'t have one', | ||
async () => { | ||
const dbConfig = { db: generateMockDb() }; | ||
|
||
const { identifier: testNewIdentifier } = await creatIdentifier(dbConfig)({ | ||
ifi: TEST_IFI, | ||
organisation: TEST_ORGANISATION, | ||
}); | ||
|
||
const { | ||
identifier: identifierWithPersona, | ||
wasCreated, | ||
} = await createPersonaAndAddToIdentifier(dbConfig)({ | ||
identifier: testNewIdentifier, | ||
personaName: 'David Tennant', | ||
}); | ||
|
||
assert.equal(identifierWithPersona.persona !== undefined, true, 'Should create and add persona to identifier'); | ||
assert.equal(wasCreated, true, 'Should create a new persona document'); | ||
}); | ||
|
||
it('Should just return identifier unchanged if it already has persona', async () => { | ||
const dbConfig = { db: generateMockDb() }; | ||
|
||
const { identifier: identifierWithPersona } = await createUpdateIdentifierPersona(dbConfig)({ | ||
ifi: TEST_IFI, | ||
organisation: TEST_ORGANISATION, | ||
personaName: 'David Tester', | ||
}); | ||
|
||
const { | ||
identifier: unchangedIdentifier, | ||
wasCreated, | ||
} = await createPersonaAndAddToIdentifier(dbConfig)({ | ||
identifier: identifierWithPersona, | ||
personaName: 'Dave Tester', | ||
}); | ||
|
||
assert.deepEqual(unchangedIdentifier, identifierWithPersona, 'Identifier should be unchanged'); | ||
assert.equal(wasCreated, false, 'We shouldn\'t have created anything, so should be false'); | ||
}); | ||
}); |
Oops, something went wrong.