Skip to content

Commit ea10a14

Browse files
committed
test: add test suite for MOG.02
Signed-off-by: Mats Johansson <extern.mats.johansson@digg.se>
1 parent 6b586a7 commit ea10a14

File tree

2 files changed

+175
-0
lines changed

2 files changed

+175
-0
lines changed

tests/unit/mog.test.ts

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,177 @@ testRule('Mog01', [
8080
errors: [],
8181
},
8282
]);
83+
testRule('Mog02', [
84+
{
85+
name: 'giltigt testfall - innehåller två resurser med två metoder vardera, samt minst en av GET, POST, PUT, DELETE eller PATCH per resurs',
86+
document: {
87+
openapi: '3.1.0',
88+
info: { version: '1.0.0' },
89+
paths: {
90+
'/pets': {
91+
get: {
92+
responses: {
93+
200: {
94+
description: 'OK',
95+
},
96+
},
97+
},
98+
head: {
99+
responses: {
100+
'200': {
101+
description: 'Resource exists',
102+
},
103+
'404': {
104+
description: 'Resource not found',
105+
},
106+
},
107+
},
108+
},
109+
'/pets/{petId}': {
110+
get: {
111+
responses: {
112+
200: {
113+
description: 'OK',
114+
},
115+
404: {
116+
description: 'Not found',
117+
},
118+
},
119+
},
120+
options: {
121+
responses: {
122+
'204': {
123+
description: 'Supported methods',
124+
},
125+
},
126+
},
127+
},
128+
},
129+
},
130+
errors: [],
131+
},
132+
{
133+
name: 'giltigt testfall - innehåller endast en resurs',
134+
document: {
135+
openapi: '3.1.0',
136+
info: { version: '1.0.0' },
137+
paths: {
138+
'/pets': {
139+
get: {
140+
responses: {
141+
200: {
142+
description: 'OK',
143+
},
144+
},
145+
},
146+
post: {
147+
responses: {
148+
201: {
149+
description: 'Created',
150+
},
151+
},
152+
},
153+
},
154+
},
155+
},
156+
errors: [
157+
{
158+
message: 'Alla API:er BÖR samtidigt designas för att uppnå nivå 3 enligt Richardson Maturity Model.',
159+
severity: DiagnosticSeverity.Warning,
160+
},
161+
],
162+
},
163+
{
164+
name: 'ogiltigt testfall - GET, POST, PUT, DELETE och PATCH saknas i ena resursen',
165+
document: {
166+
openapi: '3.1.0',
167+
info: { version: '1.0.0' },
168+
paths: {
169+
'/pets': {
170+
get: {
171+
responses: {
172+
200: {
173+
description: 'OK',
174+
},
175+
},
176+
},
177+
post: {
178+
responses: {
179+
201: {
180+
description: 'Created',
181+
},
182+
},
183+
},
184+
},
185+
'/pets/{petId}': {
186+
options: {
187+
responses: {
188+
'204': {
189+
description: 'Supported methods',
190+
},
191+
},
192+
},
193+
head: {
194+
responses: {
195+
'200': {
196+
description: 'Resource exists',
197+
},
198+
'404': {
199+
description: 'Resource not found',
200+
},
201+
},
202+
},
203+
},
204+
},
205+
},
206+
errors: [
207+
{
208+
message: 'Alla API:er BÖR samtidigt designas för att uppnå nivå 3 enligt Richardson Maturity Model.',
209+
severity: DiagnosticSeverity.Warning,
210+
},
211+
],
212+
},
213+
{
214+
name: 'ogiltigt testfall - ena resursen innehåller endast en metod',
215+
document: {
216+
openapi: '3.1.0',
217+
info: { version: '1.0.0' },
218+
paths: {
219+
'/pets': {
220+
get: {
221+
responses: {
222+
200: {
223+
description: 'OK',
224+
},
225+
},
226+
},
227+
post: {
228+
responses: {
229+
201: {
230+
description: 'Created',
231+
},
232+
},
233+
},
234+
},
235+
'/pets/{petId}': {
236+
get: {
237+
responses: {
238+
200: {
239+
description: 'OK',
240+
},
241+
404: {
242+
description: 'Not found',
243+
},
244+
},
245+
},
246+
},
247+
},
248+
},
249+
errors: [
250+
{
251+
message: 'Alla API:er BÖR samtidigt designas för att uppnå nivå 3 enligt Richardson Maturity Model.',
252+
severity: DiagnosticSeverity.Warning,
253+
},
254+
],
255+
},
256+
]);

tests/util/rulesetTest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ const ruleTypes = [
8686
ResRules.Res02,
8787
ResRules.Res06,
8888
MogRules.Mog01,
89+
MogRules.Mog02,
8990
];
9091
ruleTypes.forEach((RuleClass) => {
9192
const instance = new RuleClass();

0 commit comments

Comments
 (0)