Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change the tests ? How to use a different graphql schema/introspection results? #4

Open
Vadorequest opened this issue Mar 13, 2020 · 0 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested

Comments

@Vadorequest
Copy link
Member

There are existing tests with hard-coded introspection results and no explanation about how to change those (re-generate them from another graphql schema)

  describe('GET_LIST', () => {
    it('returns correct variables', () => {
      const introspectionResult = { // HARDCODED introspection results here
        types: [
          {
            kind: 'INPUT_OBJECT',
            name: 'PostWhereInput',
            inputFields: [{ name: 'tags_some', type: { kind: '', name: '' } }],
          },
        ],
      };
      const params = {
        filter: {
          ids: ['foo1', 'foo2'],
          tags: { id: ['tag1', 'tag2'] },
          'author.id': 'author1',
          views: 100,
        },
        pagination: { page: 10, perPage: 10 },
        sort: { field: 'sortField', order: 'DESC' },
      };

      expect(
        // @ts-ignore
        buildVariables(introspectionResult as IntrospectionResult)(
          { type: { name: 'Post' } } as Resource,
          GET_LIST,
          params,
        ),
      ).toEqual({
        where: {
          id_in: ['foo1', 'foo2'],
          tags_some: { id_in: ['tag1', 'tag2'] },
          author: { id: 'author1' },
          views: 100,
        },
        first: 10,
        orderBy: 'sortField_DESC',
        skip: 90,
      });
    });
  });

It gets much much worse with CREATE/UPDATE tests, with hundreds of lines of hardcoded introspectionResult with no explanation whatsoever on how to update those.

This is an issue when supporting new features, because I don't know how to generate a new introspection result based on a different schema. It makes things harder to test new behaviours.

If someone could shine some light about how to generate such introspectionResult variable, that'd be great!

@Vadorequest Vadorequest added good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested labels Mar 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant