Skip to content

Commit 20d7484

Browse files
wip
1 parent e64c32f commit 20d7484

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

e2e/driver.test.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ import { test, expect } from '@playwright/test';
22
import { TAXI_OWNER, execSQL, login } from './utils';
33
import { sql } from 'kysely';
44

5+
6+
const fromTime = new Date("2026-09-30T00:00:00.000Z").getTime();
7+
const toTime = new Date("2026-09-30T23:59:59.000Z").getTime();
8+
59
test('Get tours', async ({ page }) => {
610
await login(page, TAXI_OWNER);
711

812
const response = await page
913
.context()
10-
.request.get('/api/driver/tour?fromTime=1790726400000&toTime=1790812799000');
14+
.request.get(`/api/driver/tour?fromTime=${fromTime}&toTime=${toTime}`);
1115
expect(response.status()).toBe(200);
1216

1317
const responseBody = await response.json();
@@ -38,7 +42,7 @@ test('Set ticket checked', async ({ page }) => {
3842

3943
const toursResponse = await page
4044
.context()
41-
.request.get('/api/driver/tour?fromTime=1790726400000&toTime=1790812799000');
45+
.request.get(`/api/driver/tour?fromTime=${fromTime}&toTime=${toTime}`);
4246
expect(toursResponse.status()).toBe(200);
4347

4448
const tours = await toursResponse.json();
@@ -76,7 +80,7 @@ test('Set tour fare', async ({ page }) => {
7680

7781
const toursResponse = await page
7882
.context()
79-
.request.get('/api/driver/tour?fromTime=1790726400000&toTime=1790812799000');
83+
.request.get(`/api/driver/tour?fromTime=${fromTime}&toTime=${toTime}`);
8084
expect(toursResponse.status()).toBe(200);
8185

8286
const tours = await toursResponse.json();

src/routes/api/driver/fare/+server.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { db } from '$lib/server/db';
22
import { readInt } from '$lib/server/util/readForm.js';
3+
import { error } from '@sveltejs/kit';
34

45
export const PUT = async ({ url }) => {
56
const tourId = readInt(url.searchParams.get('tourId'));
67
const fare = readInt(url.searchParams.get('fare'));
78

89
if (isNaN(fare) || isNaN(tourId)) {
9-
return new Response(null, { status: 400 });
10+
error(400, { message: 'Invalid fare or tourId parameter' });
1011
}
1112

1213
const result = await db
@@ -16,7 +17,7 @@ export const PUT = async ({ url }) => {
1617
.executeTakeFirst();
1718

1819
if (result.numUpdatedRows === BigInt(0)) {
19-
return new Response(null, { status: 404 });
20+
error(404, { message: 'Tour not found' });
2021
}
2122

2223
return new Response(null, { status: 204 });

src/routes/api/driver/ticket/+server.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { db } from '$lib/server/db';
22
import { readInt } from '$lib/server/util/readForm.js';
3+
import { error } from '@sveltejs/kit';
34

45
export const PUT = async ({ url }) => {
56
const requestId = readInt(url.searchParams.get('requestId'));
67
const ticketCode = url.searchParams.get('ticketCode');
78

89
if (typeof ticketCode !== 'string' || isNaN(requestId)) {
9-
return new Response(null, { status: 400 });
10+
error(400, { message: 'Invalid ticketCode parameter' });
1011
}
1112

1213
const result = await db
@@ -17,7 +18,7 @@ export const PUT = async ({ url }) => {
1718
.executeTakeFirst();
1819

1920
if (result.numUpdatedRows === BigInt(0)) {
20-
return new Response(null, { status: 404 });
21+
error(404, { message: 'Request not found or invalid ticket code' });
2122
}
2223

2324
return new Response(null, { status: 204 });

src/routes/api/driver/tour/+server.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { getTours } from '$lib/server/db/getTours';
22
import { readInt } from '$lib/server/util/readForm.js';
3-
import { json } from '@sveltejs/kit';
3+
import { error, json } from '@sveltejs/kit';
44

55
export const GET = async ({ locals, url }) => {
66
const companyId = locals.session!.companyId!;
77
const fromTime = readInt(url.searchParams.get('fromTime'));
88
const toTime = readInt(url.searchParams.get('toTime'));
99

1010
if (isNaN(fromTime) || isNaN(toTime)) {
11-
return new Response(null, { status: 400 });
11+
error(400, { message: 'Invalid time range' });
1212
}
1313

1414
return json(await getTours(false, companyId, [fromTime, toTime]));

0 commit comments

Comments
 (0)