diff --git a/src/Squidex/app/shared/services/graphql.service.spec.ts b/src/Squidex/app/shared/services/graphql.service.spec.ts new file mode 100644 index 000000000..7a5300a97 --- /dev/null +++ b/src/Squidex/app/shared/services/graphql.service.spec.ts @@ -0,0 +1,48 @@ +/* + * Squidex Headless CMS + * + * @license + * Copyright (c) Sebastian Stehle. All rights reserved + */ + +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; +import { inject, TestBed } from '@angular/core/testing'; + +import { ApiUrlConfig, GraphQlService } from './../'; + +describe('GraphQlService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [ + HttpClientTestingModule + ], + providers: [ + GraphQlService, + { provide: ApiUrlConfig, useValue: new ApiUrlConfig('http://service/p/') } + ] + }); + }); + + afterEach(inject([HttpTestingController], (httpMock: HttpTestingController) => { + httpMock.verify(); + })); + + it('should make get request to get history events', + inject([GraphQlService, HttpTestingController], (graphQlService: GraphQlService, httpMock: HttpTestingController) => { + + let graphQlResult = null; + + graphQlService.query('my-app', { }).subscribe(result => { + graphQlResult = result; + }); + + const req = httpMock.expectOne('http://service/p/api/content/my-app/graphql'); + + expect(req.request.method).toEqual('POST'); + expect(req.request.headers.get('If-Match')).toBeNull(); + + req.flush({ result: true }); + + expect(graphQlResult).toEqual({ result: true }); + })); +}); \ No newline at end of file