rules.lua 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. local parse = require 'parse'
  2. local validate = require 'validate'
  3. local schema = require 'tests/data/schema'
  4. local function run(query)
  5. validate(schema, parse(query))
  6. end
  7. describe('rules', function()
  8. describe('uniqueOperationNames', function()
  9. it('errors if two operations have the same name', function()
  10. local query = [[
  11. query foo { }
  12. query foo { }
  13. ]]
  14. expect(function() run(query) end).to.fail.with('Multiple operations exist named')
  15. end)
  16. it('passes if operations have different names', function()
  17. local query = [[
  18. query foo { }
  19. query bar { }
  20. ]]
  21. expect(function() run(query) end).to_not.fail()
  22. end)
  23. end)
  24. describe('argumentsDefinedOnType', function()
  25. it('passes if no arguments are supplied', function()
  26. local query = [[{
  27. dog {
  28. isHouseTrained
  29. }
  30. }]]
  31. expect(function() run(query) end).to_not.fail()
  32. end)
  33. it('errors if an argument name does not match the schema', function()
  34. local query = [[{
  35. dog {
  36. doesKnowCommand(doggyCommand: SIT)
  37. }
  38. }]]
  39. expect(function() run(query) end).to.fail.with('Non%-existent argument')
  40. end)
  41. it('errors if an argument is supplied to a field that takes none', function()
  42. local query = [[{
  43. dog {
  44. name(truncateToLength: 32)
  45. }
  46. }]]
  47. expect(function() run(query) end).to.fail.with('Non%-existent argument')
  48. end)
  49. it('passes if all argument names match the schema', function()
  50. local query = [[{
  51. dog {
  52. doesKnowCommand(dogCommand: SIT)
  53. }
  54. }]]
  55. expect(function() run(query) end).to_not.fail()
  56. end)
  57. end)
  58. end)