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' ;
3
4
4
5
describe ( 'Test Graphql Service' , ( ) => {
5
6
let instance : GraphqlService ;
6
7
const ENV = `dev` ;
7
8
const STORE_VAR = `jwt-${ ENV } ` ;
9
+ const API = 'https://myApi.com' ;
8
10
9
11
beforeEach ( ( ) => {
10
12
instance = new GraphqlService ( ) ;
@@ -14,6 +16,37 @@ describe('Test Graphql Service', () => {
14
16
expect ( instance ) . toBeInstanceOf ( GraphqlService ) ;
15
17
} ) ;
16
18
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
+
17
50
it ( 'testing actionNetworkError with 403 error' , ( ) => {
18
51
const error = {
19
52
statusCode : 403
@@ -34,7 +67,7 @@ describe('Test Graphql Service', () => {
34
67
35
68
it ( 'testing actionNetworkError with 500 error' , ( ) => {
36
69
const error = {
37
- status : 500
70
+ statusCode : 500
38
71
} ;
39
72
instance . actionNetworkError ( error ) ;
40
73
const dataStorage : any = window . localStorage . getItem ( STORE_VAR ) ;
@@ -47,19 +80,6 @@ describe('Test Graphql Service', () => {
47
80
expect ( JSON . parse ( dataStorage ) ) . toBeNull ( ) ;
48
81
} ) ;
49
82
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
-
63
83
// TODO review this test
64
84
// it('testing createPublicClient', () => {
65
85
// const publicClient: any = instance.createPublicClient();
@@ -273,18 +293,13 @@ describe('Test Graphql Service', () => {
273
293
it ( 'testing mutation' , async ( ) => {
274
294
try {
275
295
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
285
300
}
286
301
}` ;
287
- const query : any = await instance . mutate ( scope , schema , variables ) ;
302
+ const query : any = await instance . mutate ( scope , schema , { input } ) ;
288
303
289
304
expect ( typeof query ) . toEqual ( typeof new Object ( ) ) ;
290
305
} catch ( e ) {
0 commit comments