1- import { GraphqlService } from '../src/graphqlService' ;
2- import { ApolloClient , gql } from '@apollo/client' ;
1+ import { DataInitType , GraphqlService } from '../src/graphqlService' ;
2+ // import {ApolloClient} from "@apollo/client";
3+ import { ApolloClient , gql } from '../src/index' ;
34
45describe ( 'Test Graphql Service' , ( ) => {
56 let instance : GraphqlService ;
67 const ENV = `dev` ;
78 const STORE_VAR = `jwt-${ ENV } ` ;
9+ const API = 'https://myApi.com' ;
810
911 beforeEach ( ( ) => {
1012 instance = new GraphqlService ( ) ;
@@ -14,6 +16,37 @@ describe('Test Graphql Service', () => {
1416 expect ( instance ) . toBeInstanceOf ( GraphqlService ) ;
1517 } ) ;
1618
19+ it ( 'testing set token' , ( ) => {
20+ instance . token = 'mytoken' ;
21+ expect ( instance . token ) . toEqual ( 'mytoken' ) ;
22+ } ) ;
23+
24+ it ( 'testing set api' , ( ) => {
25+ instance . api = API ;
26+ expect ( instance . api ) . toEqual ( API ) ;
27+ } ) ;
28+
29+ it ( 'testing set uri' , ( ) => {
30+ instance . uri = 'privateUri' ;
31+ expect ( instance . uri ) . toEqual ( 'privateUri' ) ;
32+ } ) ;
33+
34+ it ( 'testing set publicUri' , ( ) => {
35+ instance . publicUri = 'publicUri' ;
36+ expect ( instance . publicUri ) . toEqual ( 'publicUri' ) ;
37+ } ) ;
38+
39+ it ( 'testing init' , ( ) => {
40+ const initData : DataInitType = {
41+ api : API ,
42+ uri : '/api/' ,
43+ publicUri : 'public'
44+ } ;
45+
46+ instance . init ( initData ) ;
47+ expect ( instance . publicUri ) . toEqual ( 'public' ) ;
48+ } ) ;
49+
1750 it ( 'testing actionNetworkError with 403 error' , ( ) => {
1851 const error = {
1952 statusCode : 403
@@ -34,7 +67,7 @@ describe('Test Graphql Service', () => {
3467
3568 it ( 'testing actionNetworkError with 500 error' , ( ) => {
3669 const error = {
37- status : 500
70+ statusCode : 500
3871 } ;
3972 instance . actionNetworkError ( error ) ;
4073 const dataStorage : any = window . localStorage . getItem ( STORE_VAR ) ;
@@ -47,19 +80,6 @@ describe('Test Graphql Service', () => {
4780 expect ( JSON . parse ( dataStorage ) ) . toBeNull ( ) ;
4881 } ) ;
4982
50- it ( 'testing errorLink' , ( ) => {
51- // const error = {
52- // statusCode: 403,
53- // };
54- // const myMockFn = jest.fn(cb => cb(null, true));
55- // // console.log(instance.errorLink())
56- // // myMockFn((err, val) => console.log(val));
57- //
58- // // ;
59- // // const dataStorage: any = window.localStorage.getItem(STORE_VAR);
60- // // expect(JSON.parse(dataStorage)).toBeNull();
61- } ) ;
62-
6383 // TODO review this test
6484 // it('testing createPublicClient', () => {
6585 // const publicClient: any = instance.createPublicClient();
@@ -273,18 +293,13 @@ describe('Test Graphql Service', () => {
273293 it ( 'testing mutation' , async ( ) => {
274294 try {
275295 const scope = 'webApp' ;
276- const variables = { page : 4 } ;
277- const schema = `query{
278- SiteSettingGet{
279- bookingPrefix
280- currency {
281- id
282- name
283- alphabeticCode
284- }
296+ const input = { id : 4 } ;
297+ const schema = `mutation($input: GenericFilterInput!){
298+ CustomerDelete(input: $input){
299+ isSuccess
285300 }
286301 }` ;
287- const query : any = await instance . mutate ( scope , schema , variables ) ;
302+ const query : any = await instance . mutate ( scope , schema , { input } ) ;
288303
289304 expect ( typeof query ) . toEqual ( typeof new Object ( ) ) ;
290305 } catch ( e ) {
0 commit comments