Skip to content

Commit 8c0b24f

Browse files
committed
refactor(tests): consolidate NextAction and NextRoute instantiation for cleaner test cases
1 parent 2ae2e03 commit 8c0b24f

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

packages/api/tests/next-action.test.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { describe, expect, it, jest } from 'bun:test';
22
import { NextAction } from '../src/next/action.js';
33
import { z } from 'zod';
44

5+
const nextAction = new NextAction({});
6+
57
describe('Next.js Action', () => {
68
it('create nextjs server action', async () => {
7-
const aa = new NextAction({});
8-
9-
const action = aa
9+
const action = nextAction
1010
.post('/say', { actionName: 'sayHello' })
1111
.validator(
1212
z.object({
@@ -36,9 +36,7 @@ describe('Next.js Action', () => {
3636
});
3737

3838
it('create nextjs server action with bindArgs', async () => {
39-
const aa = new NextAction({});
40-
41-
const action = aa
39+
const action = nextAction
4240
.post()
4341
.validator(
4442
z.object({
@@ -58,21 +56,23 @@ describe('Next.js Action', () => {
5856
expect(action.bind(null, 'Hi')(formData)).resolves.toEqual({
5957
message: 'Hi, tom',
6058
});
59+
expect(action.bind(null, 'Hi')({ name: 'tom' })).resolves.toEqual({
60+
message: 'Hi, tom',
61+
});
6162
});
6263

6364
it('create nextjs server action with middleware', async () => {
64-
const aa = new NextAction({});
6565
const middleware = jest.fn(async (opts) => {
6666
await opts.next();
6767
});
6868

69-
const aa2 = aa.use(middleware);
69+
const withMiddleware = nextAction.use(middleware);
7070

71-
const action = aa.post().action(async () => {
71+
const action = nextAction.post().action(async () => {
7272
return { message: 'without middleware' };
7373
});
7474

75-
const action2 = aa2.post().action(async () => {
75+
const action2 = withMiddleware.post().action(async () => {
7676
return { message: 'with middleware' };
7777
});
7878

@@ -82,9 +82,7 @@ describe('Next.js Action', () => {
8282
});
8383

8484
it('create nextjs server action with selector', async () => {
85-
const aa = new NextAction({});
86-
87-
const action = aa
85+
const action = nextAction
8886
.post()
8987
.validator(
9088
z.object({

packages/api/tests/next-route.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { NextRoute } from '../src/next/route.js';
33
import { z } from 'zod';
44
import { NextRequest, NextResponse } from 'next/server.js';
55

6+
const nextRoute = new NextRoute({});
7+
68
describe('Next.js Route', () => {
79
it('should be able to create a route', async () => {
8-
const route = new NextRoute({});
9-
10-
const GET = route
10+
const GET = nextRoute
1111
.get({ action: 'getUsers' })
1212
.validator(
1313
z.object({

0 commit comments

Comments
 (0)