-
-
Notifications
You must be signed in to change notification settings - Fork 810
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(utils): Allow invalid path in getDirectiveExtensions (#6436)
Co-authored-by: Olaf Alexander <oalexander@indeed.com>
- Loading branch information
1 parent
d401903
commit 6a389e8
Showing
2 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { GraphQLObjectType } from 'graphql'; | ||
import { getDirectiveExtensions } from '../src'; | ||
|
||
describe('getDirectiveExtensions', () => { | ||
it('should return directive extensions when they are in the directives path', () => { | ||
const objectType = new GraphQLObjectType({ | ||
name: 'User', | ||
fields: () => ({}), | ||
extensions: { | ||
directives: { | ||
id: {}, | ||
}, | ||
}, | ||
}); | ||
|
||
const directiveExtensions = getDirectiveExtensions(objectType); | ||
expect(directiveExtensions).toEqual(expect.objectContaining({ id: expect.any(Object) })); | ||
}); | ||
|
||
it('should return directive extensions when they are in the a custom path', () => { | ||
const objectType = new GraphQLObjectType({ | ||
name: 'TestObject', | ||
fields: () => ({}), | ||
extensions: { | ||
custom: { | ||
directives: { | ||
path: { | ||
id: {}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const directiveExtensions = getDirectiveExtensions(objectType, undefined, [ | ||
'custom', | ||
'directives', | ||
'path', | ||
]); | ||
expect(directiveExtensions).toEqual(expect.objectContaining({ id: expect.any(Object) })); | ||
}); | ||
|
||
it('should return no directive extensions when they are no defined', () => { | ||
const objectType = new GraphQLObjectType({ | ||
name: 'TestObject', | ||
fields: () => ({}), | ||
}); | ||
const directiveExtensions = getDirectiveExtensions(objectType); | ||
expect(directiveExtensions).toEqual({}); | ||
}); | ||
|
||
it('should return no directive extensions when an invalid extension path is given', () => { | ||
const objectType = new GraphQLObjectType({ | ||
name: 'TestObject', | ||
fields: () => ({}), | ||
}); | ||
const directiveExtensions = getDirectiveExtensions(objectType, undefined, [ | ||
'not', | ||
'a', | ||
'real', | ||
'path', | ||
]); | ||
expect(directiveExtensions).toEqual({}); | ||
}); | ||
}); |