merge from ecomp a88f0072 - Modern UI
[vid.git] / vid-webpack-master / cypress / support / jsonBuilders / jsonBuilder.ts
1 export class JsonBuilder<T> implements IJsonBuilder<T>{
2   currentValue?: T;
3
4   constructor(currentValue ?: T){
5     this.currentValue = currentValue;
6   }
7   public basicJson(json: JSON, url: string, status: number, delay: number, alias: string, changeResFunc?: Function) : void {
8     this.currentValue = <T>JSON.parse(JSON.stringify(json));
9     this.currentValue = changeResFunc ? changeResFunc(this.currentValue) : this.currentValue;
10     return this.initMockCall(url, status, delay, alias);
11   }
12
13   public initMockCall(url: string, status: number, delay: number, alias: string) {
14       cy.server()
15         .route({
16           method: 'GET',
17           status: status,
18           delay : delay ? delay : 0,
19           url: url,
20           response: JSON.stringify(this.currentValue)
21         }).as(alias);
22   }
23   public basicMock(jsonPath: string, url: string ,changeResFunc?: Function) {
24     cy.readFile(jsonPath).then((res) => {
25       this.basicJson(res, url, 200, 0, url, changeResFunc);
26     })
27   }
28 }
29
30 export interface IJsonBuilder<T>{
31   basicJson(json: JSON, url: string, status: number, delay: number, alias: string, changeResFunc?: Function) : void;
32   initMockCall(url: string, status: number, delay: number, alias: string): void;
33   basicMock(jsonPath: string, url: string): void;
34 }