Skip to content

Commit

Permalink
Add troi api mock
Browse files Browse the repository at this point in the history
  • Loading branch information
malte-laukoetter committed Dec 18, 2023
1 parent 1bdce8d commit 9b7790c
Show file tree
Hide file tree
Showing 15 changed files with 1,515 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ fileignoreconfig:
checksum: f4bcc85b1fbacd2a8dd8da7675849a40024fb1f7d909b4692954412aa2473319
- filename: app/sessions.ts
allowed_patterns: [todo_create_a_secret_and_load_from_env]
- filename: app/mocks/stubs/calculationPositions.json
checksum: 4013141db60d72f20e9867642310c167f9f32d55406e7d9b788995eeac3c2111

version: ""
scopeconfig:
Expand Down
7 changes: 6 additions & 1 deletion app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@

import { PassThrough } from "node:stream";

import type { AppLoadContext, EntryContext } from "@remix-run/node";
import type { EntryContext } from "@remix-run/node";
import { createReadableStreamFromReadable } from "@remix-run/node";
import { RemixServer } from "@remix-run/react";
import isbot from "isbot";
import { renderToPipeableStream } from "react-dom/server";
import { server } from "./mocks/node";

if (process.env.MOCK_TROI_API) {
server.listen();
}

const ABORT_DELAY = 5_000;

Expand Down
35 changes: 35 additions & 0 deletions app/mocks/handlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { HttpResponse, http, passthrough } from "msw";

export const handlers = [
http.get(
"https://digitalservice.troi.software/api/v2/rest/calculationPositions",
() => {
return HttpResponse.json(require("./stubs/calculationPositions.json"));
},
),
http.get("https://digitalservice.troi.software/api/v2/rest/clients", () => {
return HttpResponse.json(require("./stubs/clients.json"));
}),
http.get("https://digitalservice.troi.software/api/v2/rest/employees", () => {
return HttpResponse.json(require("./stubs/employees.json"));
}),
http.get(
"https://digitalservice.troi.software/api/v2/rest/calendarEvents",
() => {
return HttpResponse.json(require("./stubs/calendarEvents.json"));
},
),
http.get(
"https://digitalservice.troi.software/api/v2/rest/billings/hours",
({ request }) => {
switch (new URLSearchParams(request.url).get("calculationPositionId")) {
case "4":
return HttpResponse.json(require("./stubs/billings_hours_4.json"));
case "7":
return HttpResponse.json(require("./stubs/billings_hours_7.json"));
}

return passthrough();
},
),
];
4 changes: 4 additions & 0 deletions app/mocks/node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { setupServer } from "msw/node";
import { handlers } from "./handlers";

export const server = setupServer(...handlers);
158 changes: 158 additions & 0 deletions app/mocks/stubs/billings_hours_4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
[
{
"Client": {
"Type": "ApiClient",
"Name": "DigitalService GmbH des Bundes",
"IsFavorite": false,
"IsPrintable": false,
"ParentPath": "",
"ReeEmployeeId": 0,
"ReeCpId": 0,
"ReeSubProjectId": 0,
"ReeProjectId": 0,
"ReeQuantity": 0,
"ReeDate": null,
"ReeServiceId": 0,
"id": 1,
"Id": 1,
"Path": "/clients/1",
"ETag": "20240101010203",
"IsDeleted": false,
"ClassName": "ApiSyncItem"
},
"CalculationPosition": {
"Type": "ApiCalculationPosition",
"Name": null,
"IsFavorite": false,
"IsPrintable": false,
"ParentPath": "",
"ReeEmployeeId": 0,
"ReeCpId": 0,
"ReeSubProjectId": 0,
"ReeProjectId": 0,
"ReeQuantity": 0,
"ReeDate": null,
"ReeServiceId": 0,
"id": 4,
"Id": 4,
"Path": "/calculationPositions/4",
"ETag": null,
"IsDeleted": false,
"ClassName": "ApiSyncItem"
},
"Service": null,
"Employee": {
"Type": "ApiEmployee",
"Name": null,
"IsFavorite": false,
"IsPrintable": false,
"ParentPath": "",
"ReeEmployeeId": 0,
"ReeCpId": 0,
"ReeSubProjectId": 0,
"ReeProjectId": 0,
"ReeQuantity": 0,
"ReeDate": null,
"ReeServiceId": 0,
"id": 2,
"Id": 2,
"Path": "/employees/2",
"ETag": null,
"IsDeleted": false,
"ClassName": "ApiSyncItem"
},
"Date": "2023-12-20",
"Quantity": 5,
"Remark": "Retro, Daily, Some Ticket",
"IsBillable": true,
"IsBilled": false,
"IsInvoiced": false,
"IsApproved": true,
"DisplayPath": "DigitalService / DS_23_0001 / A cool Project / Regular Engineering",
"id": 10,
"Id": 10,
"Path": "/billings/hours/10",
"ETag": "20240101010203",
"IsDeleted": false,
"documentComputedTotalNet": 0,
"ClassName": "ApiHourBilling"
},
{
"Client": {
"Type": "ApiClient",
"Name": "DigitalService GmbH des Bundes",
"IsFavorite": false,
"IsPrintable": false,
"ParentPath": "",
"ReeEmployeeId": 0,
"ReeCpId": 0,
"ReeSubProjectId": 0,
"ReeProjectId": 0,
"ReeQuantity": 0,
"ReeDate": null,
"ReeServiceId": 0,
"id": 1,
"Id": 1,
"Path": "/clients/1",
"ETag": "20240101010203",
"IsDeleted": false,
"ClassName": "ApiSyncItem"
},
"CalculationPosition": {
"Type": "ApiCalculationPosition",
"Name": null,
"IsFavorite": false,
"IsPrintable": false,
"ParentPath": "",
"ReeEmployeeId": 0,
"ReeCpId": 0,
"ReeSubProjectId": 0,
"ReeProjectId": 0,
"ReeQuantity": 0,
"ReeDate": null,
"ReeServiceId": 0,
"id": 4,
"Id": 4,
"Path": "/calculationPositions/4",
"ETag": null,
"IsDeleted": false,
"ClassName": "ApiSyncItem"
},
"Service": null,
"Employee": {
"Type": "ApiEmployee",
"Name": null,
"IsFavorite": false,
"IsPrintable": false,
"ParentPath": "",
"ReeEmployeeId": 0,
"ReeCpId": 0,
"ReeSubProjectId": 0,
"ReeProjectId": 0,
"ReeQuantity": 0,
"ReeDate": null,
"ReeServiceId": 0,
"id": 2,
"Id": 2,
"Path": "/employees/2",
"ETag": null,
"IsDeleted": false,
"ClassName": "ApiSyncItem"
},
"Date": "2023-12-22",
"Quantity": 3,
"Remark": "Another Ticket",
"IsBillable": true,
"IsBilled": false,
"IsInvoiced": false,
"IsApproved": true,
"DisplayPath": "DigitalService / DS_23_0001 / A cool Project / Regular Engineering",
"id": 11,
"Id": 11,
"Path": "/billings/hours/11",
"ETag": "20240101010203",
"IsDeleted": false,
"documentComputedTotalNet": 0,
"ClassName": "ApiHourBilling"
}
]
80 changes: 80 additions & 0 deletions app/mocks/stubs/billings_hours_7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[
{
"Client": {
"Type": "ApiClient",
"Name": "DigitalService GmbH des Bundes",
"IsFavorite": false,
"IsPrintable": false,
"ParentPath": "",
"ReeEmployeeId": 0,
"ReeCpId": 0,
"ReeSubProjectId": 0,
"ReeProjectId": 0,
"ReeQuantity": 0,
"ReeDate": null,
"ReeServiceId": 0,
"id": 1,
"Id": 1,
"Path": "/clients/1",
"ETag": "20240101010203",
"IsDeleted": false,
"ClassName": "ApiSyncItem"
},
"CalculationPosition": {
"Type": "ApiCalculationPosition",
"Name": null,
"IsFavorite": false,
"IsPrintable": false,
"ParentPath": "",
"ReeEmployeeId": 0,
"ReeCpId": 0,
"ReeSubProjectId": 0,
"ReeProjectId": 0,
"ReeQuantity": 0,
"ReeDate": null,
"ReeServiceId": 0,
"id": 7,
"Id": 7,
"Path": "/calculationPositions/7",
"ETag": null,
"IsDeleted": false,
"ClassName": "ApiSyncItem"
},
"Service": null,
"Employee": {
"Type": "ApiEmployee",
"Name": null,
"IsFavorite": false,
"IsPrintable": false,
"ParentPath": "",
"ReeEmployeeId": 0,
"ReeCpId": 0,
"ReeSubProjectId": 0,
"ReeProjectId": 0,
"ReeQuantity": 0,
"ReeDate": null,
"ReeServiceId": 0,
"id": 2,
"Id": 2,
"Path": "/employees/2",
"ETag": null,
"IsDeleted": false,
"ClassName": "ApiSyncItem"
},
"Date": "2023-12-22",
"Quantity": 5,
"Remark": "Retro, Daily, User Testing",
"IsBillable": true,
"IsBilled": false,
"IsInvoiced": false,
"IsApproved": true,
"DisplayPath": "DigitalService / DS_23_0001 / A 2nd Project / Regular Engineering",
"id": 12,
"Id": 12,
"Path": "/billings/hours/12",
"ETag": "20240101010203",
"IsDeleted": false,
"documentComputedTotalNet": 0,
"ClassName": "ApiHourBilling"
}
]
Loading

0 comments on commit 9b7790c

Please sign in to comment.