csrfToken.spec.ts 747 B

123456789101112131415161718192021222324252627
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { getCSRFToken, setCSRFToken } from '../csrfToken.ts'
  3. vi.hoisted(() => {
  4. const metaElement = document.createElement('meta')
  5. metaElement.setAttribute('name', 'csrf-token')
  6. metaElement.setAttribute('content', '1234567890ABC')
  7. vi.spyOn(document, 'querySelector').mockImplementation((): Element => {
  8. return metaElement
  9. })
  10. })
  11. describe('csrfToken handling', () => {
  12. it('get initial token', () => {
  13. expect(getCSRFToken()).toEqual('1234567890ABC')
  14. })
  15. it('set crsf token and check if this will be returned', () => {
  16. const otherValue = 'other-123456789'
  17. setCSRFToken(otherValue)
  18. expect(getCSRFToken()).toEqual(otherValue)
  19. })
  20. })