middlewares.js 925 B

1234567891011121314151617181920212223242526
  1. /* global jest:false, test:false, describe:false, expect:false */
  2. const { mergeAccessControlAllowMethods } = require('../../src/server/middlewares')
  3. describe('mergeAccessControlAllowMethods', () => {
  4. test('should properly merge', () => {
  5. const res = {
  6. get: () => 'PATCH,OPTIONS, post',
  7. header: jest.fn()
  8. }
  9. const next = jest.fn()
  10. mergeAccessControlAllowMethods(undefined, res, next)
  11. expect(res.header).toHaveBeenCalledWith('Access-Control-Allow-Methods', 'PATCH,OPTIONS,POST,GET,DELETE')
  12. expect(next).toHaveBeenCalled()
  13. })
  14. test('should also work when nothing added', () => {
  15. const res = {
  16. get: () => undefined,
  17. header: jest.fn()
  18. }
  19. const next = jest.fn()
  20. mergeAccessControlAllowMethods(undefined, res, next)
  21. expect(res.header).toHaveBeenCalledWith('Access-Control-Allow-Methods', 'GET,POST,OPTIONS,DELETE')
  22. expect(next).toHaveBeenCalled()
  23. })
  24. })