1 | import {
|
2 | Provider, ReflectiveInjector,
|
3 | } from '@angular/core';
|
4 |
|
5 | import ApolloClient from 'apollo-client';
|
6 |
|
7 | import {
|
8 | APOLLO_PROVIDERS,
|
9 | } from '../src/index';
|
10 |
|
11 | import {
|
12 | Angular2Apollo,
|
13 | defaultApolloClient,
|
14 | angularApolloClient,
|
15 | } from '../src/angular2Apollo';
|
16 |
|
17 | describe('angular2Apollo', () => {
|
18 | const client = new ApolloClient();
|
19 |
|
20 | describe('Angular2Apollo', () => {
|
21 | |
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | function rawApiCall(method: string, options = 'options', result = 'result') {
|
34 | spyOn(client, method).and.returnValue(result);
|
35 |
|
36 | const injector = ReflectiveInjector.resolveAndCreate([defaultApolloClient(client), APOLLO_PROVIDERS]);
|
37 | const service = injector.get(Angular2Apollo);
|
38 |
|
39 | expect(service[method](options)).toBe(result);
|
40 | expect(client[method]).toHaveBeenCalledWith(options);
|
41 | }
|
42 |
|
43 | describe('watchQuery()', () => {
|
44 | it('should call same method on client with same args and return it', () => {
|
45 | rawApiCall('watchQuery');
|
46 | });
|
47 | });
|
48 |
|
49 | describe('mutate()', () => {
|
50 | it('should call same method on client with same args and return it', () => {
|
51 | rawApiCall('mutate');
|
52 | });
|
53 | });
|
54 | });
|
55 |
|
56 | describe('defaultApolloClient', () => {
|
57 | it('should create a provider', () => {
|
58 | const provider = defaultApolloClient(client);
|
59 | expect(provider instanceof Provider).toBe(true);
|
60 | });
|
61 |
|
62 | it('should set a AngularApolloClient', () => {
|
63 | const injector = ReflectiveInjector.resolveAndCreate([defaultApolloClient(client)]);
|
64 | expect(injector.get(angularApolloClient)).toBe(client);
|
65 | });
|
66 | });
|
67 | });
|