Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const field: DotCMSContentTypeField = {
...dotcmsContentTypeFieldBasicMock,
contentTypeId: '1b',
id: '1'
};
this.fieldVariableService.load(field).subscribe((variables: DotFieldVariable[]) => {
expect(variables).toEqual(mockResponse.entity);
expect(0).toBe(this.lastConnection.request.method); // 2 is GET method
expect(this.lastConnection.request.url)
.toContain(`v1/contenttype/${field.contentTypeId}/fields/id/${field.id}/variables`);
});
this.lastConnection.mockRespond(
new Response(
new ResponseOptions({
body: JSON.stringify(mockResponse)
})
)
);
});
beforeEach(() => {
backend = TestBed.get(XHRBackend);
http = TestBed.get(Http);
service = new HttpHeroService(http);
fakeHeroes = makeHeroData();
let options = new ResponseOptions({status: 200, body: {data: fakeHeroes}});
response = new Response(options);
});
it('should despersonalized', () => {
const pageId = 'a';
const personaTag = 'b';
this.dotPersonalizeService.despersonalized(pageId, personaTag).subscribe();
this.lastConnection.mockRespond(
new Response(
new ResponseOptions({
body: []
})
)
);
expect(this.lastConnection.request.method).toBe(RequestMethod.Delete);
expect(this.lastConnection.request.url).toContain(
`/api/v1/personalization/pagepersonas/page/${pageId}/personalization/${personaTag}`
);
});
});
}).map(res => {
let response = new Response(res)
if (res.status < 200 || res.status >= 400) {
throw response
}
return response
})
}
private createFakeResponse(url: string, body: any, status = 200): Observable {
const responseOptionsArgs = {
body: body,
status: status,
statusText: 'OK',
url: url,
type: ResponseType.Basic
};
return Observable.of(new Response(new ResponseOptions(responseOptionsArgs)));
}
return new Observable((subscriber: Subscriber) => subscriber.error(
new Response(createErrorResponse(
interceptorArgs.requestInfo.req, 404, 'Not found'
)))
);
mockBackend.connections.subscribe(connection => {
let response = new ResponseOptions({status: 204, statusText: 'NO CONTENT'});
connection.mockRespond(new Response(response));
});
service.deleteResourceById(1)
beforeEach(async(inject([Http, Router, XHRBackend], (http: Http, router: Router, be: MockBackend) => {
backend = be;
apiService = new ApiService(http, router);
socketService = new SocketService();
authService = new AuthService(apiService, socketService, router);
fakeBuilds = buildsData.data;
let optionsBuild = new ResponseOptions({ status: 200, body: { data: fakeBuilds } });
responseBuilds = new Response(optionsBuild);
backend.connections.subscribe((c: MockConnection) => c.mockRespond(responseBuilds));
})));
backend.connections.subscribe((connection: MockConnection) => {
const options = new ResponseOptions({
body: JSON.stringify(dataToSend)
});
connection.mockRespond(new Response(options));
expect(connection.request.method).toEqual(RequestMethod.Get);
});
let currentCounter = 5;
let newCurrentSite: Site;
let loginService: LoginServiceMock = this.injector.get(LoginService);
this.siteService.switchSite$.subscribe(site => newCurrentSite = site);
let mockResponse = {
entity: {
currentSite: currentSite,
totalRecords: currentCounter,
}
};
loginService.tiggerWatchUser();
this.lastCurrentSiteConnection.mockRespond(new Response(new ResponseOptions({
body: JSON.stringify(mockResponse)
})));
tick();
expect(this.lastCurrentSiteConnection.request.url).toContain('v1/site/currentSite');
expect(currentSite).toEqual(mockResponse.entity.currentSite);
expect(currentCounter).toEqual(mockResponse.entity.totalRecords);
}));