|
| 1 | +import { expect } from 'chai'; |
| 2 | +import {objToApolloQuery, addApolloTargetToGqlQueryString} from '../'; |
| 3 | + |
| 4 | +describe('addApolloTarget()', () => { |
| 5 | + |
| 6 | + it('Converts a simple JavaScript object into a valid Apollo query', () => { |
| 7 | + const input = { |
| 8 | + appState2: { |
| 9 | + hello2: 'some arbitrary value', |
| 10 | + hello: 'arbitrary value' |
| 11 | + } |
| 12 | + }; |
| 13 | + const apolloTarget = 'client'; |
| 14 | + const expected = 'query { appState2 { hello2 hello @client } }'; |
| 15 | + expect(objToApolloQuery(input, apolloTarget)).to.equal(expected); |
| 16 | + }); |
| 17 | + |
| 18 | + it('Converts a somewhat complex JavaScript object into a valid Apollo query', () => { |
| 19 | + const input = { |
| 20 | + __typename: 'everyday-health-focuses', |
| 21 | + diet: { |
| 22 | + __typename: 'diet', |
| 23 | + title: 'Diet', |
| 24 | + id: 'diet', |
| 25 | + options: { |
| 26 | + '__typename': 'diet-options', // Why does my IDE tell me only this line needs quotation? |
| 27 | + 'calorie-count': { |
| 28 | + __typename: 'calorie-count', |
| 29 | + text: 'Calorie Count', |
| 30 | + id: 'calorie-count', |
| 31 | + icon: 'fa fa-question-circle', |
| 32 | + category: 'Diet', |
| 33 | + selected: false |
| 34 | + }, |
| 35 | + 'weight': { |
| 36 | + __typename: 'weight', |
| 37 | + text: 'Weight', |
| 38 | + id: 'weight', |
| 39 | + icon: 'fa fa-question-circle', |
| 40 | + category: 'Diet', |
| 41 | + selected: false |
| 42 | + }, |
| 43 | + 'mood': { |
| 44 | + __typename: 'mood', |
| 45 | + text: 'Mood', |
| 46 | + id: 'mood', |
| 47 | + icon: 'fa fa-question-circle', |
| 48 | + category: 'Diet', |
| 49 | + selected: false |
| 50 | + }, |
| 51 | + } |
| 52 | + }, |
| 53 | + }; |
| 54 | + const apolloTarget = 'client'; |
| 55 | + // const expected = 'query { __typename diet { __typename title id options { __typename calorie-count ' + |
| 56 | + // '{ __typename text id icon category } weight { __typename text id icon category } mood ' + |
| 57 | + // '\{ __typename text id icon category @client } } } }'; |
| 58 | + const expected = 'query { diet { title id options { calorie-count ' + |
| 59 | + '{ text id icon category } weight { text id icon category } mood ' + |
| 60 | + '\{ text id icon category @client } } } }'; |
| 61 | + expect(objToApolloQuery(input, apolloTarget)).to.equal(expected); |
| 62 | + }); |
| 63 | + |
| 64 | + it('Adds apollo target to appropriate location in a graphql query string.', () => { |
| 65 | + const input = 'query { appState2 { hello2 hello } }'; |
| 66 | + const apolloTarget = 'client'; |
| 67 | + const expected = 'query { appState2 { hello2 hello @client } }'; |
| 68 | + expect(addApolloTargetToGqlQueryString(input, apolloTarget)).to.equal(expected); |
| 69 | + }); |
| 70 | + |
| 71 | +}); |
0 commit comments