Skip to content

Commit

Permalink
Ensure tags are sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewCallis committed Dec 27, 2023
1 parent 042cfb7 commit fdfe5d0
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 48 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).

## [6.0.4](https://github.com/uttori/uttori-wiki/compare/v6.0.3...v6.0.4) - 2023-12-25

- 🛠 Ensure `tags` are always sorted

## [6.0.3](https://github.com/uttori/uttori-wiki/compare/v6.0.2...v6.0.3) - 2023-12-25

- 🛠 Fix types

## [6.0.2](https://github.com/uttori/uttori-wiki/compare/v6.0.1...v6.0.2) - 2023-12-25

- 🛠 Fix lack of exports of `EJSRenderer` & `DownloadRouter`
Expand Down
124 changes: 81 additions & 43 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"@types/express-session": "^1.17.10",
"@types/node": "^20.10.5",
"@types/supertest": "^6.0.1",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"@typescript-eslint/parser": "^6.15.0",
"@typescript-eslint/eslint-plugin": "^6.16.0",
"@typescript-eslint/parser": "^6.16.0",
"@uttori/search-provider-lunr": "^3.4.0",
"@uttori/storage-provider-json-memory": "^5",
"ava": "^6.0.1",
Expand Down
4 changes: 2 additions & 2 deletions src/wiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -1227,9 +1227,9 @@ class UttoriWiki {
// Normalize tags before save
let tags = [];
if (Array.isArray(request.body.tags)) {
tags = request.body.tags;
tags = request.body.tags.sort();
} else if (typeof request.body.tags === 'string') {
tags = request.body.tags.split(',');
tags = request.body.tags.split(',').sort();
}
tags = [...new Set(tags.map((t) => t.trim()))].filter(Boolean).sort((a, b) => a.localeCompare(b));

Expand Down
22 changes: 22 additions & 0 deletions test/saveValid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ test('saveValid: parses tags as an array', async (t) => {
t.deepEqual(document.tags, ['tag-1', 'tag-2', 'tag-3']);
});

test('saveValid: sorts tags', async (t) => {
t.plan(2);
const slug = 'test-parse-tags-array';
const server = serverSetup();
const uttori = new UttoriWiki(config, server);
const wikiFlash = sinon.spy();
await uttori.saveValid({ params: {},
body: {
title: 'Delete Page',
slug,
content: '## Delete Page',
updateDate: 1412921841841,
createDate: undefined,
tags: ['c', 'b', 'a'],
},
wikiFlash }, response, () => {});

const [document] = await uttori.hooks.fetch('storage-get', slug, this);
t.is(document.slug, slug);
t.deepEqual(document.tags, ['a', 'b', 'c']);
});

test('saveValid: parses redirects as a string', async (t) => {
t.plan(2);
const slug = 'test-parse-redirects-string';
Expand Down
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
"downlevelIteration": true,
"emitDeclarationOnly": true,
"extendedDiagnostics": true,
"lib": ["esnext", "dom", "dom.iterable", "scripthost"],
"forceConsistentCasingInFileNames": true,
"lib": [
"dom",
"esnext"
],
"module": "NodeNext",
"moduleResolution": "nodenext",
"outDir": "dist",
Expand Down

0 comments on commit fdfe5d0

Please sign in to comment.