-
-
Notifications
You must be signed in to change notification settings - Fork 625
/
cors.spec.ts
50 lines (40 loc) · 1.56 KB
/
cors.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* @adonisjs/core
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/// <reference path="../adonis-typings/index.ts" />
import test from 'japa'
import supertest from 'supertest'
import { createServer } from 'http'
import { Logger } from '@adonisjs/logger/build/standalone'
import { Profiler } from '@adonisjs/profiler/build/standalone'
import { Encryption } from '@adonisjs/encryption/build/standalone'
import { HttpContext } from '@adonisjs/http-server/build/standalone'
import { Cors } from '../src/Hooks/Cors'
import { specFixtures } from './fixtures/cors'
const encryption = new Encryption('verylongandrandom32characterskey')
test.group('Cors', () => {
specFixtures.forEach((fixture) => {
test(fixture.title, async (assert) => {
const server = createServer(async (req, res) => {
const cors = new Cors(fixture.configureOptions())
const logger = new Logger({ name: 'adonis', enabled: false, level: 'trace' })
fixture.configureRequest(req)
const ctx = HttpContext.create('/', {}, logger, new Profiler({}).create(''), encryption, req, res)
await cors.handle(ctx)
if (!ctx.response.hasLazyBody) {
ctx.response.send(null)
}
ctx.response.finish()
})
const res = await supertest(server).get('/')
fixture.assertNormal(assert, res)
const resOptions = await supertest(server).options('/')
fixture.assertOptions(assert, resOptions)
})
})
})