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

Commit

Permalink
fix: Allows persona creation without name (LLC-57) (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbishopvelti authored Jul 8, 2020
1 parent 2d64b61 commit 5eccf3e
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 29 deletions.
6 changes: 2 additions & 4 deletions src/mongoModelsRepo/createPersona.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@ import { PERSONAS_COLLECTION } from './utils/constants/collections';
export default (config: Config) => {
return async (opts: CreatePersonaOptions): Promise<CreatePersonaResult> => {
const collection = (await config.db).collection(PERSONAS_COLLECTION);
const personaId = new ObjectID();

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

// Formats the persona to be returned.
const persona: Persona = {
id: opResult.insertedId.toString(),
name: Boolean(opts.name) ? opts.name : personaId.toString(),
name: opts.name,
organisation: opts.organisation,
};

Expand Down
14 changes: 0 additions & 14 deletions src/tests/createPersona/createPersona.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import * as assert from 'assert';
import createTestPersona from '../utils/createTestPersona';
import createTestPersonaWithoutName from '../utils/createTestPersonaWithoutName';
import setup from '../utils/setup';
import { TEST_ORGANISATION } from '../utils/values';

describe('createPersona', () => {

const service = setup();

it('Should create persona', async () => {
Expand All @@ -19,16 +17,4 @@ describe('createPersona', () => {
assert.equal(actualPersona.name, 'Dave');
assert.equal(actualPersona.organisation, TEST_ORGANISATION);
});

it('Should create a persona with personaId instead name, if name not exists.', async () => {
const persona = await createTestPersonaWithoutName();
const {persona: actualPersona} = await service.getPersona({
organisation: TEST_ORGANISATION,
personaId: persona.id,
});

assert.equal(actualPersona.id, persona.id);
assert.equal(actualPersona.name, persona.id.toString());
assert.equal(actualPersona.organisation, TEST_ORGANISATION);
});
});
11 changes: 0 additions & 11 deletions src/tests/utils/createTestPersonaWithoutName.ts

This file was deleted.

0 comments on commit 5eccf3e

Please sign in to comment.