Skip to content

Commit 27f85eb

Browse files
Driver api (#188)
* wip * add driver app .gitignore * add driver api * lint + format * add driver api to server.hooks * Update package.json * reset db before unit tests --------- Co-authored-by: Felix Gündling <[email protected]>
1 parent f567c8f commit 27f85eb

File tree

19 files changed

+7566
-19
lines changed

19 files changed

+7566
-19
lines changed

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ src/lib/shadcn/*
66
.github/*
77
migrations/*
88
src/lib/openapi
9-
taxidriver-android-app
9+
driver-app

data/request.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
INSERT INTO "request" ("tour", "passengers", "bikes", "wheelchairs", "luggage", "customer") VALUES
2-
(3, 1, 0, 0, 0, 1),
3-
(3, 1, 0, 0, 0, 1),
4-
(2, 1, 0, 0, 0, 1),
5-
(1, 1, 0, 0, 0, 1);
1+
INSERT INTO "request" ("tour", "passengers", "bikes", "wheelchairs", "luggage", "customer", "ticket_code", "ticket_checked") VALUES
2+
(3, 1, 0, 0, 0, 1, 'djsjdk2349484hdhdf93hddg38d', FALSE),
3+
(3, 1, 0, 0, 0, 1, 'djsjdk2349484hdhdf93hddg38d', FALSE),
4+
(2, 1, 0, 0, 0, 1, 'djsjdk2349484hdhdf93hddg38d', FALSE),
5+
(1, 1, 0, 0, 0, 1, 'djsjdk2349484hdhdf93hddg38d', FALSE);

data/user.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ INSERT INTO "user" ("email", "is_taxi_owner", "is_admin", "password_hash", "name
88
('[email protected]', 't', 'f', '$argon2id$v=19$m=19456,t=2,p=1$jxW4oxa3l0tg+OG3+4lllw$l5TN76xuwWqc01KNBHB37WukqjmqjKsm/ZBF2y+NvPY', 'John', NULL, 5, 't'),
99
('[email protected]', 't', 'f', '$argon2id$v=19$m=19456,t=2,p=1$dviKXplqYeVGdRA+UztyDg$/rQUv5OVgKufsy6VqYtFhXfE6jaHOCV6oE+3aDZVGMo', 'John', NULL, 6, 't'),
1010
('[email protected]', 't', 'f', '$argon2id$v=19$m=19456,t=2,p=1$B7mjUX8IFZv+1G/jiu2dSQ$xGhHcG8PKvDYLwydw2aVVqaaovdjFanlIrBjF0TgDkI', 'John', NULL, 7, 't'),
11-
('[email protected]', 't', 'f', '$argon2id$v=19$m=19456,t=2,p=1$6zvrI5rYSzw+NP8hRZ1Yxg$pAY9o3o3rhlCNGo2zVwP/Kq5YVOrm6yvLrqaSDeWxpw', 'John', NULL, 8, 't');
11+
('[email protected]', 't', 'f', '$argon2id$v=19$m=19456,t=2,p=1$6zvrI5rYSzw+NP8hRZ1Yxg$pAY9o3o3rhlCNGo2zVwP/Kq5YVOrm6yvLrqaSDeWxpw', 'John', NULL, 8, 't'),
12+
('[email protected]', 'f', 'f', '$argon2id$v=19$m=19456,t=2,p=1$6zvrI5rYSzw+NP8hRZ1Yxg$pAY9o3o3rhlCNGo2zVwP/Kq5YVOrm6yvLrqaSDeWxpw', 'John', NULL, 1, 't');

driver-app/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.gradle
2+
.idea

e2e/driver.test.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { test, expect } from '@playwright/test';
2+
import { TAXI_OWNER, execSQL, login } from './utils';
3+
import { sql } from 'kysely';
4+
5+
test('Get tours', async ({ page }) => {
6+
await login(page, TAXI_OWNER);
7+
8+
const response = await page
9+
.context()
10+
.request.get('/api/driver/tour?fromTime=1790726400000&toTime=1790812799000');
11+
expect(response.status()).toBe(200);
12+
13+
const responseBody = await response.json();
14+
expect(responseBody).toHaveLength(1);
15+
expect(responseBody[0]).toHaveProperty('tourId');
16+
expect(responseBody[0]).toHaveProperty('licensePlate', 'GR-TU-11');
17+
expect(responseBody[0]).toHaveProperty('events');
18+
19+
const events = responseBody[0]['events'];
20+
expect(events).toHaveLength(2);
21+
expect(events[0]).toHaveProperty('requestId');
22+
23+
const requestId = events[0]['requestId'];
24+
expect(requestId).not.toBeNaN();
25+
});
26+
27+
test('Get vehicles', async ({ page }) => {
28+
await login(page, TAXI_OWNER);
29+
30+
const response = await page.context().request.get('/api/driver/vehicle');
31+
expect(response.status()).toBe(200);
32+
33+
const responseBody = await response.json();
34+
expect(responseBody).toHaveLength(1);
35+
expect(responseBody[0]).toHaveProperty('licensePlate', 'GR-TU-11');
36+
});
37+
38+
test('Set ticket checked', async ({ page }) => {
39+
await login(page, TAXI_OWNER);
40+
41+
const toursResponse = await page
42+
.context()
43+
.request.get('/api/driver/tour?fromTime=1790726400000&toTime=1790812799000');
44+
expect(toursResponse.status()).toBe(200);
45+
46+
const tours = await toursResponse.json();
47+
expect(tours).toHaveLength(1);
48+
expect(tours[0]).toHaveProperty('events');
49+
50+
const events = tours[0]['events'];
51+
expect(events).toHaveLength(2);
52+
expect(events[0]).toHaveProperty('requestId');
53+
54+
const requestId = events[0]['requestId'];
55+
expect(requestId).not.toBeNaN();
56+
57+
const ticketCode = 'a7d421840cf89e052d7c1aa74caf66d8';
58+
await execSQL(sql`UPDATE "request" SET ticket_code = ${ticketCode} WHERE id = ${requestId}`);
59+
60+
const response = await page
61+
.context()
62+
.request.post(`/api/driver/ticket?requestId=${requestId}&ticketCode=${ticketCode}`);
63+
expect(response.status()).toBe(200);
64+
});
65+
66+
test('Set tour fare', async ({ page }) => {
67+
await login(page, TAXI_OWNER);
68+
69+
const toursResponse = await page
70+
.context()
71+
.request.get('/api/driver/tour?fromTime=1790726400000&toTime=1790812799000');
72+
expect(toursResponse.status()).toBe(200);
73+
74+
const tours = await toursResponse.json();
75+
expect(tours).toHaveLength(1);
76+
expect(tours[0]).toHaveProperty('tourId');
77+
78+
const tourId = tours[0]['tourId'];
79+
expect(tourId).not.toBeNaN();
80+
81+
const fare = 1234;
82+
83+
const response = await page
84+
.context()
85+
.request.post(`/api/driver/fare?tourId=${tourId}&fare=${fare}`);
86+
expect(response.status()).toBe(200);
87+
});

e2e/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ export async function addVehicle(page: Page, licensePlate: string) {
100100
await page.goto('/taxi/availability');
101101
await page.waitForTimeout(500);
102102
await page.getByTestId('add-vehicle').click();
103-
await page.waitForTimeout(500);
103+
await page.waitForTimeout(1000);
104104
await page.getByPlaceholder('DA-AB-1234').fill(licensePlate);
105105
await page.getByLabel('3 Passagiere').check();
106106
await page.getByTestId('create-vehicle').click();
107107
}
108108

109109
export async function moveMouse(page: Page, id: string) {
110110
const element = page.getByTestId(id).locator('div');
111-
const { x, y, width, height } = await element.boundingBox();
111+
const { x, y, width, height } = (await element.boundingBox())!;
112112
await page.mouse.move(x + width / 2, y + height / 2);
113113
}

migrations/2024-07-01.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ export async function up(db) {
8686
.addColumn('luggage', 'integer', (col) => col.notNull())
8787
.addColumn('tour', 'integer', (col) => col.references('tour.id').notNull())
8888
.addColumn('customer', 'integer', (col) => col.references('user.id').notNull())
89+
.addColumn('ticket_code', 'varchar', (col) => col.notNull())
90+
.addColumn('ticket_checked', 'boolean', (col) => col.notNull())
8991
.execute();
9092

9193
await db.schema
@@ -304,8 +306,8 @@ export async function up(db) {
304306
OUT v_request_id INTEGER
305307
) AS $$
306308
BEGIN
307-
INSERT INTO request (passengers, wheelchairs, bikes, luggage, customer, tour)
308-
VALUES (p_request.passengers, p_request.wheelchairs, p_request.bikes, p_request.luggage, p_request.customer, p_tour_id)
309+
INSERT INTO request (passengers, wheelchairs, bikes, luggage, customer, tour, ticket_code, ticket_checked)
310+
VALUES (p_request.passengers, p_request.wheelchairs, p_request.bikes, p_request.luggage, p_request.customer, p_tour_id, md5(random()::text), FALSE)
309311
RETURNING id INTO v_request_id;
310312
END;
311313
$$ LANGUAGE plpgsql;

0 commit comments

Comments
 (0)