2 /* eslint-disable capitalized-comments */
6 const assert
= require('assert');
7 const sinon
= require('sinon');
9 describe('slug', function () {
10 const Slug
= require('../../src/slug');
12 const maxSlugLength
= 86;
14 afterEach(function () {
18 describe('newSlug', function () {
19 it('generates a slug from seed', async
function () {
21 const seedSHA512b64trunc
= 'z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg-SpIdNs6c5H0NE8XYXysP.DGNKHfuwvY7kxvUdBeoGlODJ6+SfaPg';
22 const result
= await Slug
.newSlug(seed
);
23 assert
.strictEqual(result
, seedSHA512b64trunc
);
25 it('generates a random slug', async
function () {
26 const result
= await Slug
.newSlug();
27 assert
.strictEqual(result
.length
, maxSlugLength
);
29 it('only makes a slug so big', async
function () {
31 const result
= await Slug
.newSlug(undefined, slugLen
);
32 assert
.strictEqual(result
.length
, maxSlugLength
);
36 describe('makeSlugGenerator', function () {
37 it('makes a slug generator which generates a slug', async
function () {
39 const sg
= Slug
.makeSlugGenerator(seed
);
40 const { done
, value
} = await sg
.next();
42 assert
.strictEqual(value
.length
, 5);
44 it('makes a slug generator which generates many slugs', async
function () {
46 const sg
= Slug
.makeSlugGenerator(seed
, 5, 8);
48 const checkNext
= async (expected
) => {
49 const { done
, value
} = await sg
.next();
51 assert
.strictEqual(value
, expected
);
53 const checkNextLen
= async (expected
) => {
54 const { done
, value
} = await sg
.next();
56 assert
.strictEqual(value
.length
, expected
);
59 await
checkNext('z4PhN');
60 await
checkNext('z4PhNX');
61 await
checkNext('z4PhNX7');
62 await
checkNext('z4PhNX7v');
63 await
checkNextLen(5);
64 await
checkNextLen(6);
65 await
checkNextLen(7);
66 await
checkNextLen(8);
67 await
checkNextLen(5);
68 await
checkNextLen(6);
70 }); // makeSlugGenerator