| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- import { CustomFields } from 'shared/shared-types';
- import { addGraphQLCustomFields } from './graphql-custom-fields';
- describe('addGraphQLCustomFields()', () => {
- it('uses JSON scalar if no custom fields defined', () => {
- const input = `
- type Product {
- id: ID
- }
- `;
- const customFieldConfig: CustomFields = {
- Product: [],
- };
- const result = addGraphQLCustomFields(input, customFieldConfig);
- expect(result).toMatchSnapshot();
- });
- it('extends a type', () => {
- const input = `
- type Product {
- id: ID
- }
- `;
- const customFieldConfig: CustomFields = {
- Product: [{ name: 'available', type: 'boolean' }],
- };
- const result = addGraphQLCustomFields(input, customFieldConfig);
- expect(result).toMatchSnapshot();
- });
- it('extends a type with a translation', () => {
- const input = `
- type Product {
- id: ID
- translations: [ProductTranslation!]!
- }
- type ProductTranslation {
- id: ID
- }
- `;
- const customFieldConfig: CustomFields = {
- Product: [{ name: 'available', type: 'boolean' }, { name: 'shortName', type: 'localeString' }],
- };
- const result = addGraphQLCustomFields(input, customFieldConfig);
- expect(result).toMatchSnapshot();
- });
- it('extends a type with a Create input', () => {
- const input = `
- type Product {
- id: ID
- }
- input CreateProductInput {
- image: String
- }
- `;
- const customFieldConfig: CustomFields = {
- Product: [{ name: 'available', type: 'boolean' }, { name: 'shortName', type: 'localeString' }],
- };
- const result = addGraphQLCustomFields(input, customFieldConfig);
- expect(result).toMatchSnapshot();
- });
- it('extends a type with an Update input', () => {
- const input = `
- type Product {
- id: ID
- }
- input UpdateProductInput {
- image: String
- }
- `;
- const customFieldConfig: CustomFields = {
- Product: [{ name: 'available', type: 'boolean' }, { name: 'shortName', type: 'localeString' }],
- };
- const result = addGraphQLCustomFields(input, customFieldConfig);
- expect(result).toMatchSnapshot();
- });
- it('extends a type with a Create input and a translation', () => {
- const input = `
- type Product {
- id: ID
- }
- type ProductTranslation {
- id: ID
- }
- input ProductTranslationInput {
- id: ID
- }
- input CreateProductInput {
- image: String
- }
- `;
- const customFieldConfig: CustomFields = {
- Product: [{ name: 'available', type: 'boolean' }, { name: 'shortName', type: 'localeString' }],
- };
- const result = addGraphQLCustomFields(input, customFieldConfig);
- expect(result).toMatchSnapshot();
- });
- it('extends a type with SortParameters', () => {
- const input = `
- type Product {
- id: ID
- }
- input ProductSortParameter {
- id: SortOrder
- }
- enum SortOrder {
- ASC
- DESC
- }
- `;
- const customFieldConfig: CustomFields = {
- Product: [{ name: 'available', type: 'boolean' }, { name: 'shortName', type: 'localeString' }],
- };
- const result = addGraphQLCustomFields(input, customFieldConfig);
- expect(result).toMatchSnapshot();
- });
- it('extends a type with FilterParameters', () => {
- const input = `
- type Product {
- name: String
- }
- input ProductFilterParameter {
- id: StringOperators
- }
- input StringOperators {
- eq: String
- }
- input NumberOperators {
- eq: Float
- }
- input DateOperators {
- eq: String
- }
- input BooleanOperators {
- eq: Boolean
- }
- `;
- const customFieldConfig: CustomFields = {
- Product: [
- { name: 'available', type: 'boolean' },
- { name: 'shortName', type: 'localeString' },
- { name: 'rating', type: 'float' },
- { name: 'published', type: 'datetime' },
- ],
- };
- const result = addGraphQLCustomFields(input, customFieldConfig);
- expect(result).toMatchSnapshot();
- });
- });
|