Skip to content
This repository was archived by the owner on May 5, 2023. It is now read-only.

Commit 178726d

Browse files
authored
fix: Uses persona ID for personas without a name (LLC-57) (#293)
1 parent ad3bc94 commit 178726d

4 files changed

Lines changed: 32 additions & 8 deletions

File tree

src/mongoModelsRepo/createPersona.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ import { PERSONAS_COLLECTION } from './utils/constants/collections';
88
export default (config: Config) => {
99
return async (opts: CreatePersonaOptions): Promise<CreatePersonaResult> => {
1010
const collection = (await config.db).collection(PERSONAS_COLLECTION);
11-
12-
const docToInsert = {
13-
name: opts.name,
14-
organisation: new ObjectID(opts.organisation),
15-
};
11+
const personaId = new ObjectID();
1612

1713
// Docs: http://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html#insertOne
1814
// Docs: http://bit.ly/insertOneWriteOpResult
19-
const opResult = await collection.insertOne(docToInsert, {});
15+
const opResult = await collection.insertOne({
16+
_id: personaId,
17+
name: Boolean(opts.name) ? opts.name : personaId.toString(),
18+
organisation: new ObjectID(opts.organisation),
19+
}, {});
2020

2121
// Formats the persona to be returned.
2222
const persona: Persona = {
2323
id: opResult.insertedId.toString(),
24-
name: opts.name,
24+
name: Boolean(opts.name) ? opts.name : personaId.toString(),
2525
organisation: opts.organisation,
2626
};
2727

src/tests/createPersona/createPersona.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as assert from 'assert';
22
import createTestPersona from '../utils/createTestPersona';
3+
import createTestPersonaWithoutName from '../utils/createTestPersonaWithoutName';
34
import setup from '../utils/setup';
45
import { TEST_ORGANISATION } from '../utils/values';
56

@@ -18,4 +19,16 @@ describe('createPersona', () => {
1819
assert.equal(actualPersona.name, 'Dave');
1920
assert.equal(actualPersona.organisation, TEST_ORGANISATION);
2021
});
22+
23+
it('Should create a persona with personaId instead name, if name not exists.', async () => {
24+
const persona = await createTestPersonaWithoutName();
25+
const {persona: actualPersona} = await service.getPersona({
26+
organisation: TEST_ORGANISATION,
27+
personaId: persona.id,
28+
});
29+
30+
assert.equal(actualPersona.id, persona.id);
31+
assert.equal(actualPersona.name, persona.id.toString());
32+
assert.equal(actualPersona.organisation, TEST_ORGANISATION);
33+
});
2134
});

src/tests/utils/createTestPersona.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// tslint:disable-next-line:no-unused
22
import PersonaModel from '../../models/Persona';
33
import service from '../../tester';
4-
import { TEST_ORGANISATION } from '../utils/values';
4+
import { TEST_ORGANISATION } from './values';
55

66
export default async (name?: string, organisation: string = TEST_ORGANISATION) => {
77
const {persona} = await service.createPersona({
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// tslint:disable-next-line:no-unused
2+
import PersonaModel from '../../models/Persona';
3+
import service from '../../tester';
4+
import { TEST_ORGANISATION } from './values';
5+
6+
export default async (organisation: string = TEST_ORGANISATION) => {
7+
const {persona} = await service.createPersona({
8+
organisation,
9+
});
10+
return persona;
11+
};

0 commit comments

Comments
 (0)