Skip to content

Commit 6b590be

Browse files
committed
Update test dependencies and fix API route compatibility
1 parent 98eaaec commit 6b590be

7 files changed

Lines changed: 238 additions & 144 deletions

File tree

__test__/api-profiles-create.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('POST /user', () => {
1313
describe('given a request with firstName, lastName, and email', () => {
1414
test('should respond with statusCode 200 and return document persisted', async () => {
1515
await testApiHandler({
16-
handler,
16+
pagesHandler: handler,
1717
test: async ({ fetch }) => {
1818
let response = await fetch({
1919
method: 'POST',
@@ -46,7 +46,7 @@ describe('POST /user', () => {
4646
const expected = { statusCode: 400, message: 'email is required' };
4747
test(`should respond with statusCode 400 and message: '${expected.message}'`, async () => {
4848
await testApiHandler({
49-
handler,
49+
pagesHandler: handler,
5050
test: async ({ fetch }) => {
5151
let response = await fetch({
5252
method: 'POST',

__test__/api-profiles-delete.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { testApiHandler } from 'next-test-api-route-handler';
2+
import { randomUUID } from 'node:crypto';
23
import handler from '../pages/api/user';
3-
import { v4 } from 'uuid';
44
import { connectToDatabase } from '../util/couchbase';
55

66
describe('DELETE /user?pid={id}', () => {
77
describe('given we pass a pid as request param', () => {
8-
const id = v4();
8+
const id = randomUUID();
99

1010
beforeEach(async () => {
1111
const { profileCollection } = await connectToDatabase();
@@ -24,7 +24,7 @@ describe('DELETE /user?pid={id}', () => {
2424

2525
test('should respond with status code 200 to DELETE', async () => {
2626
await testApiHandler({
27-
handler,
27+
pagesHandler: handler,
2828
params: { pid: id },
2929
test: async ({ fetch }) => {
3030
let response = await fetch({

__test__/api-profiles-read.test.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { testApiHandler } from 'next-test-api-route-handler';
2+
import { randomUUID } from 'node:crypto';
23
import handler from '../pages/api/user';
3-
import { v4 } from 'uuid';
44
import { connectToDatabase } from '../util/couchbase';
55

66
const profile1 = {
7-
pid: v4(),
7+
pid: randomUUID(),
88
firstName: 'Joe',
99
lastName: 'Schmoe',
1010
email: 'joe.schmoe@couchbase.com',
1111
};
1212
const profile2 = {
13-
pid: v4(),
13+
pid: randomUUID(),
1414
firstName: 'John',
1515
lastName: 'Dear',
1616
email: 'john.dear@couchbase.com',
@@ -29,8 +29,7 @@ beforeAll(async () => {
2929
describe('GET /user', () => {
3030
test('responds 200 to GET all', async () => {
3131
await testApiHandler({
32-
handler,
33-
params: { search: 'jo' },
32+
pagesHandler: handler,
3433
test: async ({ fetch }) => {
3534
let response = await fetch({ method: 'GET' });
3635
let jsonResponse = await response.json();
@@ -44,16 +43,18 @@ describe('GET /user', () => {
4443
},
4544
});
4645
});
46+
4747
test('responds 200 to GET with search string', async () => {
4848
await testApiHandler({
49-
handler,
49+
pagesHandler: handler,
50+
params: { search: 'jo' },
5051
test: async ({ fetch }) => {
5152
let response = await fetch({ method: 'GET' });
5253
let jsonResponse = await response.json();
5354
expect(jsonResponse).toEqual(
5455
expect.arrayContaining([
55-
expect.objectContaining(profile2),
5656
expect.objectContaining(profile1),
57+
expect.objectContaining(profile2),
5758
])
5859
);
5960
expect(response.status).toBe(200);

__test__/api-profiles-update.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { testApiHandler } from 'next-test-api-route-handler';
2+
import { randomUUID } from 'node:crypto';
23
import handler from '../pages/api/user';
3-
import { v4 } from 'uuid';
44
import { connectToDatabase } from '../util/couchbase';
55

66
describe('PUT /user?pid={id}', () => {
77
describe('given the profile object is updated', () => {
8-
const id = v4();
8+
const id = randomUUID();
99
const initialProfile = {
1010
pid: id,
1111
firstName: 'Joseph',
@@ -29,7 +29,7 @@ describe('PUT /user?pid={id}', () => {
2929

3030
test('should respond with status code 200 OK and updated values of document returned', async () => {
3131
await testApiHandler({
32-
handler,
32+
pagesHandler: handler,
3333
params: { pid: id },
3434
test: async ({ fetch }) => {
3535
let response = await fetch({

0 commit comments

Comments
 (0)