diff --git a/apps/jsonthing-api/CHANGELOG.md b/apps/jsonthing-api/CHANGELOG.md index 7276ff1..0589e76 100644 --- a/apps/jsonthing-api/CHANGELOG.md +++ b/apps/jsonthing-api/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [0.3.0](https://github.com/lharti/jsonthing/compare/jsonthing-api@0.2.0...jsonthing-api@0.3.0) (2024-11-12) + + +### Features + +* **api/docs:** add multiple doc title candidates ([7e1e760](https://github.com/lharti/jsonthing/commit/7e1e76023ed7544d2cde94e805e61ca2a658adea)) + + + + + # [0.2.0](https://github.com/lharti/jsonthing/compare/jsonthing-api@0.1.3...jsonthing-api@0.2.0) (2024-11-12) diff --git a/apps/jsonthing-api/package.json b/apps/jsonthing-api/package.json index 4bd3043..2b66fc1 100644 --- a/apps/jsonthing-api/package.json +++ b/apps/jsonthing-api/package.json @@ -1,6 +1,6 @@ { "name": "jsonthing-api", - "version": "0.2.0", + "version": "0.3.0", "description": "", "author": "", "private": true, diff --git a/apps/jsonthing-api/src/routes/docs/constants/docs.constants.ts b/apps/jsonthing-api/src/routes/docs/constants/docs.constants.ts index a5377b3..d50d688 100644 --- a/apps/jsonthing-api/src/routes/docs/constants/docs.constants.ts +++ b/apps/jsonthing-api/src/routes/docs/constants/docs.constants.ts @@ -1,4 +1,20 @@ -export const DEFAULT_DOC_NAME = 'Untitled' +export const DEFAULT_DOC_TITLE_CANDIDATES = [ + 'Add Your Touch', + 'Make Me Yours', + 'Do Your Thing', + 'Edit me', + 'Modify me', + 'Change It Up', + 'Untitled', +] + +export function getRandomDefaultTitle(): string { + const randomIndex = Math.floor( + Math.random() * DEFAULT_DOC_TITLE_CANDIDATES.length, + ) + + return DEFAULT_DOC_TITLE_CANDIDATES[randomIndex] +} export const DEFAULT_DOC_CONTENT = { tagline: 'JSON Made Easy', diff --git a/apps/jsonthing-api/src/routes/docs/service/docs.service.spec.ts b/apps/jsonthing-api/src/routes/docs/service/docs.service.spec.ts index c958428..f9ef50c 100644 --- a/apps/jsonthing-api/src/routes/docs/service/docs.service.spec.ts +++ b/apps/jsonthing-api/src/routes/docs/service/docs.service.spec.ts @@ -4,7 +4,7 @@ import { } from '@/common/helpers/fixtures' import { DEFAULT_DOC_CONTENT, - DEFAULT_DOC_NAME, + DEFAULT_DOC_TITLE_CANDIDATES, } from '@/routes/docs/constants' import { docsModel } from '@/routes/docs/model/doc.schema' import { @@ -72,21 +72,18 @@ describe('docsService', () => { const result = await docsService.createDoc() - const defaultDocValues = { - title: DEFAULT_DOC_NAME, - content: DEFAULT_DOC_CONTENT, - } - expect(result).toStrictEqual({ id: expect.stringMatching(OBJECT_ID_PATTERN), + title: expect.toBeOneOf(DEFAULT_DOC_TITLE_CANDIDATES), + + content: DEFAULT_DOC_CONTENT, + contentText: JSON.stringify( - defaultDocValues.content, + DEFAULT_DOC_CONTENT, null, 2, ), - - ...defaultDocValues, }) }) diff --git a/apps/jsonthing-api/src/routes/docs/service/docs.service.ts b/apps/jsonthing-api/src/routes/docs/service/docs.service.ts index 1f563f2..9cc75c8 100644 --- a/apps/jsonthing-api/src/routes/docs/service/docs.service.ts +++ b/apps/jsonthing-api/src/routes/docs/service/docs.service.ts @@ -7,7 +7,10 @@ import { } from '@nestjs/common' import { InjectModel } from '@nestjs/mongoose' import mongoose from 'mongoose' -import { DEFAULT_DOC_CONTENT, DEFAULT_DOC_NAME } from '../constants' +import { + DEFAULT_DOC_CONTENT, + getRandomDefaultTitle, +} from '../constants' import { Doc, DocsModel } from '../model' @Injectable() @@ -21,7 +24,7 @@ export class DocsService { public createDoc(createDocPayload?: CreateDocDto): Promise { const docPayload = { - title: createDocPayload?.title || DEFAULT_DOC_NAME, + title: createDocPayload?.title || getRandomDefaultTitle(), content: createDocPayload?.content || DEFAULT_DOC_CONTENT, }