Skip to content

Commit

Permalink
feat(api/docs): add multiple doc title candidates (#106)
Browse files Browse the repository at this point in the history
* feat(api/docs): add multiple doc title candidates

* chore(release): bump versions

 - [email protected]
  • Loading branch information
lharti authored Nov 12, 2024
1 parent 7aa6853 commit b20a577
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 13 deletions.
11 changes: 11 additions & 0 deletions apps/jsonthing-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]@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/[email protected]@0.2.0) (2024-11-12)


Expand Down
2 changes: 1 addition & 1 deletion apps/jsonthing-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsonthing-api",
"version": "0.2.0",
"version": "0.3.0",
"description": "",
"author": "",
"private": true,
Expand Down
18 changes: 17 additions & 1 deletion apps/jsonthing-api/src/routes/docs/constants/docs.constants.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
15 changes: 6 additions & 9 deletions apps/jsonthing-api/src/routes/docs/service/docs.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
})
})

Expand Down
7 changes: 5 additions & 2 deletions apps/jsonthing-api/src/routes/docs/service/docs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -21,7 +24,7 @@ export class DocsService {

public createDoc(createDocPayload?: CreateDocDto): Promise<Doc> {
const docPayload = {
title: createDocPayload?.title || DEFAULT_DOC_NAME,
title: createDocPayload?.title || getRandomDefaultTitle(),

content: createDocPayload?.content || DEFAULT_DOC_CONTENT,
}
Expand Down

0 comments on commit b20a577

Please sign in to comment.