summaryrefslogtreecommitdiff
path: root/packages/astro/test/api-routes.test.js
blob: a911de3327b5736ff6f8899840492a1110ffdc0c (plain) (blame)
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
import { expect } from 'chai';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
import * as fs from 'fs';
import { FormData, File } from 'node-fetch';

describe('API routes', () => {
	/** @type {import('./test-utils').Fixture} */
	let fixture;

	before(async () => {
		fixture = await loadFixture({ root: './fixtures/api-routes/' });
		await fixture.build();
	});

	describe('Deprecated API', () => {
		it('two argument supported', async () => {
			const one = JSON.parse(await fixture.readFile('/old-api/twoarg/one.json'));
			expect(one).to.deep.equal({
				param: 'one',
				pathname: '/old-api/twoarg/one.json',
			});
			const two = JSON.parse(await fixture.readFile('/old-api/twoarg/two.json'));
			expect(two).to.deep.equal({
				param: 'two',
				pathname: '/old-api/twoarg/two.json',
			});
		});

		it('param first argument is supported', async () => {
			const one = JSON.parse(await fixture.readFile('/old-api/onearg/one.json'));
			expect(one).to.deep.equal({
				param: 'one',
			});
		});
	});

	describe('1.0 API', () => {
		it('Receives a context argument', async () => {
			const one = JSON.parse(await fixture.readFile('/context/data/one.json'));
			expect(one).to.deep.equal({
				param: 'one',
				pathname: '/context/data/one.json',
			});
		});
	});
});