forked from maplestory-music/maplebgm-db
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bgm.test.js
27 lines (26 loc) · 951 Bytes
/
bgm.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const Ajv = require('ajv');
const schema = require('./schema');
const bgmDatabase = require('./bgm');
describe('bgm database', () => {
test('should adhere to json schema', () => {
let ajv = new Ajv({allErrors: true});
let validate = ajv.compile(schema);
let valid = validate(bgmDatabase);
if (!valid) {
console.error(validate.errors);
}
expect(valid).toEqual(true);
});
test('should be sorted by filename', () => {
let songNames = bgmDatabase.map(song => song.filename);
let sortedSongNames = bgmDatabase.map(song => song.filename);
sortedSongNames.sort((a, b) =>
a.localeCompare(b, 'en', {ignorePunctuation: true}));
expect(songNames).toEqual(sortedSongNames);
});
test('filename should be unique', () => {
let songNames = bgmDatabase.map(song => song.filename);
let distinctSongNames = new Set(songNames);
expect(songNames.length).toEqual(distinctSongNames.size);
});
});