20 lines
697 B
JavaScript
20 lines
697 B
JavaScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { api, setCsrf } from '../src/api.js'
|
|
|
|
test('mutation sends the session CSRF token and credentials', async () => {
|
|
let request
|
|
globalThis.fetch = async (url, options) => {
|
|
request = { url, options }
|
|
return new Response(null, { status: 204 })
|
|
}
|
|
setCsrf('csrf-test')
|
|
|
|
await api('/tools/1/status', { method: 'PATCH', body: '{"status":0}' })
|
|
|
|
assert.equal(request.url, '/api/admin/tools/1/status')
|
|
assert.equal(request.options.credentials, 'same-origin')
|
|
assert.equal(request.options.headers['X-CSRF-Token'], 'csrf-test')
|
|
assert.equal(request.options.headers['Content-Type'], 'application/json')
|
|
})
|