-
Notifications
You must be signed in to change notification settings - Fork 1
/
deprecation-validator.js
74 lines (45 loc) · 2.32 KB
/
deprecation-validator.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'use strict';
const assert = require('assert');
const sinon = require('sinon');
const fs = require('fs-extra');
const ymljs = require('yamljs');
const deprecationValidator = require('../lib/deprecation-validator');
const titleIdentifier = fs.readFileSync(process.cwd() + '/tests/mocks/schemas/deprecated/edit-with-deprecated-title-identifier.yml');
const titleBeforeId = fs.readFileSync(process.cwd() + '/tests/mocks/schemas/deprecated/edit-with-deprecated-title-before-id.yml');
const titleAfterId = fs.readFileSync(process.cwd() + '/tests/mocks/schemas/deprecated/edit-with-deprecated-title-after-id.yml');
const titleComponents = fs.readFileSync(process.cwd() + '/tests/mocks/schemas/deprecated/edit-with-deprecated-title-components.yml');
const deprecatedSchemaIdentifier = ymljs.parse(titleIdentifier.toString());
const deprecatedSchemaBeforeId = ymljs.parse(titleBeforeId.toString());
const deprecatedSchemaAfterId = ymljs.parse(titleAfterId.toString());
const deprecatedSchemaTitleComponents = ymljs.parse(titleComponents.toString());
describe('deprecation-validator', () => {
afterEach(() => {
sinon.restore();
});
it('should find a deprecated property identifier in header', async () => {
const executeSpy = sinon.spy(deprecationValidator, 'execute');
deprecationValidator.execute(deprecatedSchemaIdentifier);
assert(executeSpy.calledOnce);
});
it('should return if it dosen\'t have header', async () => {
const executeSpy = sinon.spy(deprecationValidator, 'execute');
delete deprecatedSchemaIdentifier.header;
deprecationValidator.execute(deprecatedSchemaIdentifier);
assert(executeSpy.calledOnce);
});
it('should find a deprecated property afterId in header', async () => {
const executeSpy = sinon.spy(deprecationValidator, 'execute');
deprecationValidator.execute(deprecatedSchemaAfterId);
assert(executeSpy.calledOnce);
});
it('should find a deprecated property beforeId in header', async () => {
const executeSpy = sinon.spy(deprecationValidator, 'execute');
deprecationValidator.execute(deprecatedSchemaBeforeId);
assert(executeSpy.calledOnce);
});
it('should find a deprecated property components in header', async () => {
const executeSpy = sinon.spy(deprecationValidator, 'execute');
deprecationValidator.execute(deprecatedSchemaTitleComponents);
assert(executeSpy.calledOnce);
});
});