-
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.
🚧 progress(eid): Deduplicate insertions.
- Loading branch information
1 parent
f6fbfe1
commit 9b7a812
Showing
9 changed files
with
155 additions
and
12 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,31 @@ | ||
import {assert} from 'chai'; | ||
|
||
import {randomUserId, server} from '../../../_test/fixtures'; | ||
|
||
import {Eids} from '../../collection/eids'; | ||
|
||
import {newEidData} from '../../_dev/populate/eids'; | ||
import invoke from '../invoke'; | ||
|
||
import insertFromEid from './insertFromEid'; | ||
|
||
server(__filename, () => { | ||
it('does not create duplicate eid entries', async () => { | ||
const userId = randomUserId(); | ||
|
||
const eid = newEidData(); | ||
|
||
await invoke(insertFromEid, {userId}, [eid]); | ||
const oldEntry = await Eids.findOneAsync({owner: userId}); | ||
assert.isDefined(oldEntry); | ||
|
||
await invoke(insertFromEid, {userId}, [eid]); | ||
const entries = await Eids.find({owner: userId}).fetchAsync(); | ||
|
||
assert.strictEqual(entries.length, 1); | ||
|
||
const {createdAt, lastUsedAt} = entries[0]!; | ||
assert.strictEqual(createdAt.valueOf(), oldEntry.createdAt.valueOf()); | ||
assert.isAbove(lastUsedAt.valueOf(), oldEntry.lastUsedAt.valueOf()); | ||
}); | ||
}); |
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,35 @@ | ||
import {assert} from 'chai'; | ||
|
||
import {randomUserId, server} from '../../../_test/fixtures'; | ||
|
||
import {newPatient} from '../../_dev/populate/patients'; | ||
import invoke from '../invoke'; | ||
|
||
import {newEidData} from '../../_dev/populate/eids'; | ||
|
||
import {Eids} from '../../collection/eids'; | ||
|
||
import updateFromEid from './updateFromEid'; | ||
|
||
server(__filename, () => { | ||
it('does not create duplicate eid entries', async () => { | ||
const userId = randomUserId(); | ||
|
||
const eid = newEidData(); | ||
|
||
const patientId = await newPatient({userId}); | ||
|
||
await invoke(updateFromEid, {userId}, [patientId, eid]); | ||
const oldEntry = await Eids.findOneAsync({owner: userId}); | ||
assert.isDefined(oldEntry); | ||
|
||
await invoke(updateFromEid, {userId}, [patientId, eid]); | ||
const entries = await Eids.find({owner: userId}).fetchAsync(); | ||
|
||
assert.strictEqual(entries.length, 1); | ||
|
||
const {createdAt, lastUsedAt} = entries[0]!; | ||
assert.strictEqual(createdAt.valueOf(), oldEntry.createdAt.valueOf()); | ||
assert.isAbove(lastUsedAt.valueOf(), oldEntry.lastUsedAt.valueOf()); | ||
}); | ||
}); |
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