diff --git a/__tests__/unit/services/sitemap.test.ts b/__tests__/unit/services/sitemap.test.ts new file mode 100644 index 0000000..79b3b3d --- /dev/null +++ b/__tests__/unit/services/sitemap.test.ts @@ -0,0 +1,40 @@ +import { expect, test } from 'vitest' +import { generateSitemapString } from '../../../src/services/sitemap'; +import { Sitemap } from '../../../src/models/sitemap'; + +test('generate sitemap.xml', async () => { + + const data: Array = [ + { + loc: '/articles/abc', + lastMod: '2020-01-01' + }, + { + loc: '/articles/def', + lastMod: '2022-02-02' + }, + { + loc: '/diary/', + lastMod: '2023-03-03' + } + ] + + const result = await generateSitemapString('https://example.com', data); + expect(result.replace(/\s/g,"")).toEqual( + ` + + https://example.com/articles/abc + 2020-01-01 + + + https://example.com/articles/def + 2022-02-02 + + + https://example.com/diary/ + 2023-03-03 + + + `.replace(/\s/g,"") + ); +});