Skip to content

Commit 43d8516

Browse files
Add tests for slugify
Also switched from test to it for consistency
1 parent 3fc8a55 commit 43d8516

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

test/services/lib/bing-utils.js

+20-9
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
11
const Lab = require('@hapi/lab')
22
const { expect } = require('@hapi/code')
3-
const { experiment, test } = exports.lab = Lab.script()
4-
const { formatName } = require('../../../server/services/lib/bing-utils')
3+
const { experiment, it } = exports.lab = Lab.script()
4+
const { formatName, slugify } = require('../../../server/services/lib/bing-utils')
55

66
experiment('bing utils', () => {
77
experiment('formatName', () => {
8-
test('Repeating parts are removed', async () => {
8+
it('Repeating parts are removed', async () => {
99
expect(formatName('Middlesbrough, Middlesbrough')).to.equal('Middlesbrough')
1010
})
11-
test('Similar parts are not removed', async () => {
11+
it('Similar parts are not removed', async () => {
1212
expect(formatName('Durham, County Durham')).to.equal('Durham, County Durham')
1313
})
14-
test('City qualifier "City Of" is removed', async () => {
14+
it('City qualifier "City Of" is removed', async () => {
1515
expect(formatName('Bristol, City Of Bristol')).to.equal('Bristol')
1616
})
17-
test('City qualifier "City of" is removed (ie case insensitive)', async () => {
17+
it('City qualifier "City of" is removed (ie case insensitive)', async () => {
1818
expect(formatName('Bristol, City of Bristol')).to.equal('Bristol')
1919
})
20-
test('City qualifier "Greater" is removed', async () => {
20+
it('City qualifier "Greater" is removed', async () => {
2121
expect(formatName('London, Greater London')).to.equal('London')
2222
})
23-
test('City qualifier removed from neighbourhood', async () => {
23+
it('City qualifier removed from neighbourhood', async () => {
2424
expect(formatName('Camberwell, London, Greater London')).to.equal('Camberwell, London')
2525
})
2626
experiment('Error handling', () => {
27-
test('Fails gracefully with undefined name', async () => {
27+
it('Fails gracefully with undefined name', async () => {
2828
expect(formatName()).to.equal('')
2929
})
3030
})
3131
})
32+
experiment('slugify', () => {
33+
it('Simple name is slugified', async () => {
34+
expect(slugify('Leeds, West Yorkshire')).to.equal('leeds-west-yorkshire')
35+
})
36+
it('Non-alphanumerics (!) are preserved', async () => {
37+
expect(slugify('Westward Ho!, Bideford, Devon')).to.equal('westward-ho!-bideford-devon')
38+
})
39+
it('Non-alphanumerics (\') are preserved', async () => {
40+
expect(slugify('Bishop\'s Stortford')).to.equal('bishop\'s-stortford')
41+
})
42+
})
3243
})

0 commit comments

Comments
 (0)