Skip to content

Commit

Permalink
Driver api (#188)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
steffenheger and felixguendling authored Feb 13, 2025
1 parent f567c8f commit 27f85eb
Show file tree
Hide file tree
Showing 19 changed files with 7,566 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ src/lib/shadcn/*
.github/*
migrations/*
src/lib/openapi
taxidriver-android-app
driver-app
10 changes: 5 additions & 5 deletions data/request.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
INSERT INTO "request" ("tour", "passengers", "bikes", "wheelchairs", "luggage", "customer") VALUES
(3, 1, 0, 0, 0, 1),
(3, 1, 0, 0, 0, 1),
(2, 1, 0, 0, 0, 1),
(1, 1, 0, 0, 0, 1);
INSERT INTO "request" ("tour", "passengers", "bikes", "wheelchairs", "luggage", "customer", "ticket_code", "ticket_checked") VALUES
(3, 1, 0, 0, 0, 1, 'djsjdk2349484hdhdf93hddg38d', FALSE),
(3, 1, 0, 0, 0, 1, 'djsjdk2349484hdhdf93hddg38d', FALSE),
(2, 1, 0, 0, 0, 1, 'djsjdk2349484hdhdf93hddg38d', FALSE),
(1, 1, 0, 0, 0, 1, 'djsjdk2349484hdhdf93hddg38d', FALSE);
3 changes: 2 additions & 1 deletion data/user.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ INSERT INTO "user" ("email", "is_taxi_owner", "is_admin", "password_hash", "name
('[email protected]', 't', 'f', '$argon2id$v=19$m=19456,t=2,p=1$jxW4oxa3l0tg+OG3+4lllw$l5TN76xuwWqc01KNBHB37WukqjmqjKsm/ZBF2y+NvPY', 'John', NULL, 5, 't'),
('[email protected]', 't', 'f', '$argon2id$v=19$m=19456,t=2,p=1$dviKXplqYeVGdRA+UztyDg$/rQUv5OVgKufsy6VqYtFhXfE6jaHOCV6oE+3aDZVGMo', 'John', NULL, 6, 't'),
('[email protected]', 't', 'f', '$argon2id$v=19$m=19456,t=2,p=1$B7mjUX8IFZv+1G/jiu2dSQ$xGhHcG8PKvDYLwydw2aVVqaaovdjFanlIrBjF0TgDkI', 'John', NULL, 7, 't'),
('[email protected]', 't', 'f', '$argon2id$v=19$m=19456,t=2,p=1$6zvrI5rYSzw+NP8hRZ1Yxg$pAY9o3o3rhlCNGo2zVwP/Kq5YVOrm6yvLrqaSDeWxpw', 'John', NULL, 8, 't');
('[email protected]', 't', 'f', '$argon2id$v=19$m=19456,t=2,p=1$6zvrI5rYSzw+NP8hRZ1Yxg$pAY9o3o3rhlCNGo2zVwP/Kq5YVOrm6yvLrqaSDeWxpw', 'John', NULL, 8, 't'),
('[email protected]', 'f', 'f', '$argon2id$v=19$m=19456,t=2,p=1$6zvrI5rYSzw+NP8hRZ1Yxg$pAY9o3o3rhlCNGo2zVwP/Kq5YVOrm6yvLrqaSDeWxpw', 'John', NULL, 1, 't');
2 changes: 2 additions & 0 deletions driver-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.gradle
.idea
87 changes: 87 additions & 0 deletions e2e/driver.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { test, expect } from '@playwright/test';
import { TAXI_OWNER, execSQL, login } from './utils';
import { sql } from 'kysely';

test('Get tours', async ({ page }) => {
await login(page, TAXI_OWNER);

const response = await page
.context()
.request.get('/api/driver/tour?fromTime=1790726400000&toTime=1790812799000');
expect(response.status()).toBe(200);

const responseBody = await response.json();
expect(responseBody).toHaveLength(1);
expect(responseBody[0]).toHaveProperty('tourId');
expect(responseBody[0]).toHaveProperty('licensePlate', 'GR-TU-11');
expect(responseBody[0]).toHaveProperty('events');

const events = responseBody[0]['events'];
expect(events).toHaveLength(2);
expect(events[0]).toHaveProperty('requestId');

const requestId = events[0]['requestId'];
expect(requestId).not.toBeNaN();
});

test('Get vehicles', async ({ page }) => {
await login(page, TAXI_OWNER);

const response = await page.context().request.get('/api/driver/vehicle');
expect(response.status()).toBe(200);

const responseBody = await response.json();
expect(responseBody).toHaveLength(1);
expect(responseBody[0]).toHaveProperty('licensePlate', 'GR-TU-11');
});

test('Set ticket checked', async ({ page }) => {
await login(page, TAXI_OWNER);

const toursResponse = await page
.context()
.request.get('/api/driver/tour?fromTime=1790726400000&toTime=1790812799000');
expect(toursResponse.status()).toBe(200);

const tours = await toursResponse.json();
expect(tours).toHaveLength(1);
expect(tours[0]).toHaveProperty('events');

const events = tours[0]['events'];
expect(events).toHaveLength(2);
expect(events[0]).toHaveProperty('requestId');

const requestId = events[0]['requestId'];
expect(requestId).not.toBeNaN();

const ticketCode = 'a7d421840cf89e052d7c1aa74caf66d8';
await execSQL(sql`UPDATE "request" SET ticket_code = ${ticketCode} WHERE id = ${requestId}`);

const response = await page
.context()
.request.post(`/api/driver/ticket?requestId=${requestId}&ticketCode=${ticketCode}`);
expect(response.status()).toBe(200);
});

test('Set tour fare', async ({ page }) => {
await login(page, TAXI_OWNER);

const toursResponse = await page
.context()
.request.get('/api/driver/tour?fromTime=1790726400000&toTime=1790812799000');
expect(toursResponse.status()).toBe(200);

const tours = await toursResponse.json();
expect(tours).toHaveLength(1);
expect(tours[0]).toHaveProperty('tourId');

const tourId = tours[0]['tourId'];
expect(tourId).not.toBeNaN();

const fare = 1234;

const response = await page
.context()
.request.post(`/api/driver/fare?tourId=${tourId}&fare=${fare}`);
expect(response.status()).toBe(200);
});
4 changes: 2 additions & 2 deletions e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ export async function addVehicle(page: Page, licensePlate: string) {
await page.goto('/taxi/availability');
await page.waitForTimeout(500);
await page.getByTestId('add-vehicle').click();
await page.waitForTimeout(500);
await page.waitForTimeout(1000);
await page.getByPlaceholder('DA-AB-1234').fill(licensePlate);
await page.getByLabel('3 Passagiere').check();
await page.getByTestId('create-vehicle').click();
}

export async function moveMouse(page: Page, id: string) {
const element = page.getByTestId(id).locator('div');
const { x, y, width, height } = await element.boundingBox();
const { x, y, width, height } = (await element.boundingBox())!;
await page.mouse.move(x + width / 2, y + height / 2);
}
6 changes: 4 additions & 2 deletions migrations/2024-07-01.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export async function up(db) {
.addColumn('luggage', 'integer', (col) => col.notNull())
.addColumn('tour', 'integer', (col) => col.references('tour.id').notNull())
.addColumn('customer', 'integer', (col) => col.references('user.id').notNull())
.addColumn('ticket_code', 'varchar', (col) => col.notNull())
.addColumn('ticket_checked', 'boolean', (col) => col.notNull())
.execute();

await db.schema
Expand Down Expand Up @@ -304,8 +306,8 @@ export async function up(db) {
OUT v_request_id INTEGER
) AS $$
BEGIN
INSERT INTO request (passengers, wheelchairs, bikes, luggage, customer, tour)
VALUES (p_request.passengers, p_request.wheelchairs, p_request.bikes, p_request.luggage, p_request.customer, p_tour_id)
INSERT INTO request (passengers, wheelchairs, bikes, luggage, customer, tour, ticket_code, ticket_checked)
VALUES (p_request.passengers, p_request.wheelchairs, p_request.bikes, p_request.luggage, p_request.customer, p_tour_id, md5(random()::text), FALSE)
RETURNING id INTO v_request_id;
END;
$$ LANGUAGE plpgsql;
Expand Down
Loading

0 comments on commit 27f85eb

Please sign in to comment.