Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
refactor(Object Transform tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Dec 1, 2019
1 parent 733c2c2 commit 4bc6e26
Showing 1 changed file with 41 additions and 11 deletions.
52 changes: 41 additions & 11 deletions src/test/testAlternateMergeSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
ExtendSchema,
WrapType,
FilterRootFields,
FilterObjectFields,
} from '../transforms';
import {
propertySchema,
Expand Down Expand Up @@ -426,8 +427,10 @@ describe('transform object fields', () => {
});
});

describe('rename object fields', () => {
it('should work', async () => {
describe.only('transform object fields', () => {
let schema: GraphQLSchema;

before(() => {
const ITEM = {
id: '123',
camel_case: "I'm a camel!",
Expand Down Expand Up @@ -464,7 +467,13 @@ describe('rename object fields', () => {
}
});

const schema = transformSchema(itemSchema, [
schema = transformSchema(itemSchema, [
new FilterObjectFields((_typeName, fieldName) => {
if (fieldName === 'id') {
return false;
}
return true;
}),
new RenameObjectFields((_typeName, fieldName) => {
if (fieldName === 'camel_case') {
return 'camelCase';
Expand All @@ -478,34 +487,28 @@ describe('rename object fields', () => {
return fieldName;
}),
]);
});

it('renaming should work', async () => {
const result = await graphql(
schema,
`
query {
item {
id
camelCase
}
items {
edges {
node {
id
camelCase
}
}
}
}
`,
{},
{},
{
pid: 'p1',
},
);

const TRANSFORMED_ITEM = {
id: '123',
camelCase: "I'm a camel!",
};

Expand All @@ -520,6 +523,33 @@ describe('rename object fields', () => {
},
});
});

it('filtering should work', async () => {
const result = await graphql(
schema,
`
query {
items {
edges {
node {
id
}
}
}
}
`,
);

expect(result).to.deep.equal({
errors: [{
locations: [{
column: 17,
line: 6,
}],
message: 'Cannot query field \"id\" on type \"Item\".',
}],
});
});
});

describe('filter and rename object fields', () => {
Expand Down

0 comments on commit 4bc6e26

Please sign in to comment.