forked from finos/architecture-as-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface-id-exists-on-node.spec.ts
More file actions
127 lines (113 loc) · 4.49 KB
/
interface-id-exists-on-node.spec.ts
File metadata and controls
127 lines (113 loc) · 4.49 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { interfaceIdExistsOnNode } from './interface-id-exists-on-node';
describe('interfaceIdExistsOnNode', () => {
it('should return an empty array when there is no input', () => {
const input = null;
const context = {
document: {
data: {}
}
};
const result = interfaceIdExistsOnNode(input, null, context);
expect(result).toEqual([]);
});
it('should return an empty array when input has no interfaces', () => {
const input = {};
const context = {
document: {
data: {}
}
};
const result = interfaceIdExistsOnNode(input, null, context);
expect(result).toEqual([]);
});
it('should return a message when input is a connect relationship missing a node', () => {
const input = { interfaces: ['intf1'] };
const context = {
document: {
data: {}
},
path: ['/relationships/0/connects/destination']
};
const result = interfaceIdExistsOnNode(input, null, context);
expect(result.length).toBe(1);
expect(result[0].message).toBe('Invalid connects relationship - no node defined.');
expect(result[0].path).toEqual(['/relationships/0/connects/destination']);
});
it('should return an empty array when the node and interface exists', () => {
const input = { node: 'node1', interfaces: ['intf1'] };
const context = {
document: {
data: {
nodes: [
{
'unique-id': 'node1',
'interfaces': [
{'unique-id': 'intf1'} // will match this interface
]
}
]
}
}
};
const result = interfaceIdExistsOnNode(input, null, context);
expect(result).toEqual([]);
});
it('should return a message when the target node has no interfaces', () => {
const input = { node: 'node1', interfaces: ['intf2'] };
const context = {
document: {
data: {
nodes: [{'unique-id': 'node1'}]
}
},
path: ['/relationships/0/connects/destination']
};
const result = interfaceIdExistsOnNode(input, null, context);
expect(result.length).toBe(1);
expect(result[0].message).toBe(`Node with unique-id ${input.node} has no interfaces defined, expected interfaces [${input.interfaces}].`);
});
it('should return a message when the interface does not exist', () => {
const input = { node: 'node1', interfaces: ['intf2'] };
const context = {
document: {
data: {
nodes: [
{
'unique-id': 'node1',
'interfaces': [
{'unique-id': 'intf1'}
]
}
]
}
},
path: ['/relationships/0/connects/destination']
};
const result = interfaceIdExistsOnNode(input, null, context);
expect(result.length).toBe(1);
expect(result[0].message).toBe(`Referenced interface with ID '${input.interfaces[0]}' was not defined on the node with ID '${input.node}'.`);
expect(result[0].path).toEqual(['/relationships/0/connects/destination']);
});
it('should return a message when one interface does not exist', () => {
const input = { node: 'node1', interfaces: ['intf1', 'intf2'] };
const context = {
document: {
data: {
nodes: [
{
'unique-id': 'node1',
'interfaces': [
{'unique-id': 'intf1'}
]
}
]
}
},
path: ['/relationships/0/connects/destination']
};
const result = interfaceIdExistsOnNode(input, null, context);
expect(result.length).toBe(1);
expect(result[0].message).toBe(`Referenced interface with ID '${input.interfaces[1]}' was not defined on the node with ID '${input.node}'.`);
expect(result[0].path).toEqual(['/relationships/0/connects/destination']);
});
});