Skip to content

Commit

Permalink
entity-renderer: add some tests for enableSchemaUrlRedirect if disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovicm67 committed Dec 17, 2024
1 parent 54e5245 commit 86e4332
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions packages/entity-renderer/test/entity-renderer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,69 @@ describe('@zazuko/trifid-entity-renderer', () => {
strictEqual(res.status, 200)
})
})

describe('disabled', () => {
beforeEach(async () => {
const trifidInstance = await createTrifidInstance(trifidConfigUrl, 'warn', {
enableSchemaUrlRedirect: false,
})
trifidListener = await trifidInstance.start()
})

afterEach(async () => {
await trifidListener.close()
})

it('should not redirect for non-html content', async () => {
const entityUrl = `${getListenerURL(trifidListener)}/test/shouldRedirect`
const res = await fetch(entityUrl, { redirect: 'manual' })
strictEqual(res.status, 200)
})

it('should not redirect for html content', async () => {
const entityUrl = `${getListenerURL(trifidListener)}/test/shouldRedirect`
const res = await fetch(entityUrl, {
headers: {
accept: 'text/html',
},
redirect: 'manual',
})
strictEqual(res.status, 200)
})

it('should not redirect when disableSchemaUrlRedirect=true', async () => {
const entityUrl = `${getListenerURL(trifidListener)}/test/shouldRedirect?disableSchemaUrlRedirect=true`
const res = await fetch(entityUrl, {
headers: {
accept: 'text/html',
},
redirect: 'manual',
})
strictEqual(res.status, 200)
})

it('should not redirect when x-disable-schema-url-redirect=true', async () => {
const entityUrl = `${getListenerURL(trifidListener)}/test/shouldRedirect`
const res = await fetch(entityUrl, {
headers: {
accept: 'text/html',
'x-disable-schema-url-redirect': 'true',
},
redirect: 'manual',
})
strictEqual(res.status, 200)
})

it('should not redirect when the value is not an xsd:anyURI', async () => {
const entityUrl = `${getListenerURL(trifidListener)}/test/shouldNotRedirect`
const res = await fetch(entityUrl, {
headers: {
accept: 'text/html',
},
redirect: 'manual',
})
strictEqual(res.status, 200)
})
})
})
})

0 comments on commit 86e4332

Please sign in to comment.