@@ -3,69 +3,65 @@ import { PRODUCT_SEARCH_BFF_SPEC_BACKWARD_INCOMPATIBLE } from "../../specNames";
33import { ServiceSpecConfigPage } from "../../../page-objects/service-spec-config-page" ;
44import { Page } from "@playwright/test" ;
55
6- test . describe ( "API Specification — Backward Incompatibility" , ( ) => {
7- test (
8- "Adding path parameter to existing endpoint to check backward compatibility" ,
9- { tag : [ "@spec" , "@bccIncompatibleTest" , "@eyes" ] } ,
10- async ( { page, eyes } , testInfo ) => {
11- const configPage = await setupConfigPage ( page , testInfo , eyes ) ;
12-
13- await test . step ( "Change /products to /products/{id} in the editor" , async ( ) => {
14- await configPage . editSpecInEditor ( " /products:" , " /products/{id}:" ) ;
15- } ) ;
16-
17- await assertBccFailure (
18- configPage ,
19- "This API exists in the old contract but not in the new contract" ,
20- 1 ,
21- ) ;
22- } ,
23- ) ;
6+ const INCOMPATIBLE_SCENARIOS = [
7+ {
8+ name : "Add path parameter to existing endpoint" ,
9+ oldText : " /products:" ,
10+ newText : " /products/{id}:" ,
11+ lineCount : 0 ,
12+ expectedErrorCount : 1 ,
13+ expectedDetail :
14+ "This API exists in the old contract but not in the new contract" ,
15+ isExpectedFailure : false ,
16+ } ,
17+ {
18+ name : "Remove a response status code" ,
19+ oldText : " '201':" ,
20+ newText : " '299':" ,
21+ lineCount : 0 ,
22+ expectedErrorCount : 1 ,
23+ expectedDetail :
24+ "This API exists in the old contract but not in the new contract" ,
25+ isExpectedFailure : false ,
26+ } ,
27+ {
28+ name : "Change optional parameter to required" ,
29+ oldText : " required: false" ,
30+ newText : " required: true" ,
31+ lineCount : 0 ,
32+ expectedErrorCount : 1 ,
33+ expectedDetail :
34+ 'New specification expects query param "type" in the request' ,
35+ isExpectedFailure : false ,
36+ } ,
37+ {
38+ name : "Remove all content from requestBody" ,
39+ oldText : " content:" ,
40+ newText : "" ,
41+ lineCount : 4 ,
42+ expectedErrorCount : 1 ,
43+ expectedDetail :
44+ "This is no body in the new specification, but json object in the old specification" ,
45+ isExpectedFailure : false ,
46+ } ,
47+ ] ;
2448
25- test (
26- "Removing a response status code is a backward incompatible change" ,
27- { tag : [ "@spec" , "@bccIncompatibleTest" , "@eyes" , "@expected-failure" ] } ,
28- async ( { page, eyes } , testInfo ) => {
29- test . fail (
30- true ,
31- "Error count does not match with acutal error. Needs fixing by dev" ,
32- ) ;
33- const configPage = await setupConfigPage ( page , testInfo , eyes ) ;
34-
35- await test . step ( "Change response status code '201' to '299' under /products in the editor" , async ( ) => {
36- await configPage . editSpecInEditor ( " '201':" , " '299':" ) ;
37- } ) ;
49+ test . describe ( "API Specification — Backward Incompatibility" , ( ) => {
50+ let configPage : ServiceSpecConfigPage ;
3851
39- await assertBccFailure (
40- configPage ,
41- "This API exists in the old contract but not in the new contract" ,
42- 2 ,
43- ) ;
44- } ,
45- ) ;
52+ test . beforeEach ( async ( { page, eyes } , testInfo ) => {
53+ configPage = await setupConfigPage ( page , testInfo , eyes ) ;
54+ } ) ;
4655
4756 test (
48- "Making a required parameter optional is a backward incompatible change" ,
49- { tag : [ "@spec" , "@bccIncompatibleTest" , "@eyes" , "@expected-failure" ] } ,
50- async ( { page, eyes } , testInfo ) => {
51- test . fail (
52- true ,
53- "Error count does not match with acutal error. Needs fixing by dev" ,
54- ) ;
55- const configPage = await setupConfigPage ( page , testInfo , eyes ) ;
56-
57- await test . step ( "Making optional Parameter required" , async ( ) => {
58- await configPage . editSpecInEditor (
59- " required: false" ,
60- " required: true" ,
61- ) ;
62- } ) ;
63-
64- await assertBccFailure (
65- configPage ,
66- 'New specification expects query param "type" in the request but it is missing from the old specification' ,
67- 3 ,
68- ) ;
57+ "Run all incompatibility scenarios in one session" ,
58+ { tag : [ "@spec" , "@bccIncompatibleTest" , "@eyes" ] } ,
59+ async ( ) => {
60+ for ( const scenario of INCOMPATIBLE_SCENARIOS ) {
61+ await test . step ( `Testing scenario: ${ scenario . name } ` , async ( ) => {
62+ await configPage . verifyIncompatibilityScenario ( scenario ) ;
63+ } ) ;
64+ }
6965 } ,
7066 ) ;
7167} ) ;
@@ -77,39 +73,6 @@ async function setupConfigPage(page: Page, testInfo: any, eyes: any) {
7773 eyes ,
7874 PRODUCT_SEARCH_BFF_SPEC_BACKWARD_INCOMPATIBLE ,
7975 ) ;
80- await test . step ( `Go to Spec page for Service Spec: '${ PRODUCT_SEARCH_BFF_SPEC_BACKWARD_INCOMPATIBLE } '` , async ( ) => {
81- await configPage . gotoHomeAndOpenSidebar ( ) ;
82- await configPage . sideBar . selectSpec (
83- PRODUCT_SEARCH_BFF_SPEC_BACKWARD_INCOMPATIBLE ,
84- ) ;
85- await configPage . openSpecTab ( ) ;
86- } ) ;
87- return configPage ;
88- }
8976
90- async function assertBccFailure (
91- configPage : ServiceSpecConfigPage ,
92- expectedErrorDetail : string ,
93- expectedErrorCount : number ,
94- ) {
95- await test . step ( "Run Backward Compatibility test and assert failure toast" , async ( ) => {
96- await configPage . runBackwardCompatibilityTest ( ) ;
97- const toastText = await configPage . getAlertMessageText ( ) ;
98- expect . soft ( toastText ) . toContain ( "Backward compatibility test failed" ) ;
99- await configPage . dismissAlert ( ) ;
100- } ) ;
101-
102- await test . step ( "Assert error dropdown heading shows 1 error" , async ( ) => {
103- await configPage . toggleBccErrorSection ( true ) ;
104- const { summary } = await configPage . getBccErrorDetails ( ) ;
105- expect
106- . soft ( summary )
107- . toContain ( `Backward Compatibility found ${ expectedErrorCount } error` ) ;
108- } ) ;
109-
110- await test . step ( "Assert error detail describes the contract mismatch" , async ( ) => {
111- const { details } = await configPage . getBccErrorDetails ( ) ;
112- expect . soft ( details . length ) . toBeGreaterThan ( 0 ) ;
113- expect . soft ( details [ 0 ] ) . toContain ( expectedErrorDetail ) ;
114- } ) ;
77+ return configPage ;
11578}
0 commit comments