Skip to content

Commit

Permalink
feat: add retrieve cars planning
Browse files Browse the repository at this point in the history
  • Loading branch information
haroldcohen committed Oct 19, 2023
1 parent b3029c0 commit 9633aeb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/core/useCases/common/cursors/encodeDecode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export const encodeCursor = (cursor: string, order: string): string => {
return btoa(`${order === 'gte' ? 'next' : 'prev'}___${cursor}`);
}

/**
* Decodes a cursor address from a base64 format.
*
* @param cursor The cursor address to decode
*/
export const decodeCursor = (cursor: string): DecodedCursor => {
if (cursor === '') {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "reflect-metadata";
import {container} from "tsyringe";
import DateParser from "tests/utils/dateParser";
import {fa, faker} from "@faker-js/faker";
import {faker} from "@faker-js/faker";
import {advanceTo} from "jest-date-mock";
import {v4} from "uuid";
import _ from "lodash";
Expand Down Expand Up @@ -407,6 +407,42 @@ describe.each([
...buildCarTestCases(5)
] as CarTestCaseEntry[], ['licensePlate'], ['asc']),
},
{
query: {
actor: {
email: faker.internet.email({provider: "megahertz.com"}),
},
agency: {
name: 'MegaHertz Paris Opera',
},
startDate: 'today',
endDate: 'in 10 days',
limit: 3,
},
models: [
{
id: '086e0785-b788-479d-a2b2-a193f9805859',
name: 'Aston Martin V8',
}
],
cars: _.orderBy([
{
id: v4(),
model: {
id: '086e0785-b788-479d-a2b2-a193f9805859',
},
licensePlate: 'AA-123-AA',
rentals: [
{
id: '080cf232-38c8-4caa-ad7e-c5d401b3b9de',
pickupDateTime: 'today',
dropOffDateTime: 'in 2 days',
}
],
},
...buildCarTestCases(5)
] as CarTestCaseEntry[], ['licensePlate'], ['asc']),
},
])(
"Given I am logged in as front desk employee $query.actor.email from agency $query.agency.name " +
"And I have more than $query.limit car(s) " +
Expand Down Expand Up @@ -441,8 +477,8 @@ describe.each([
});
})

test(`Then It should return a list of ${testCase.cars.length} car(s)`, async () => {
const numExecutions = testCase.cars.length / testCase.query.limit;
test(`Then It should return a list of ${testCase.query.limit} car(s)`, async () => {
const numExecutions = testCase.cars.length % testCase.query.limit;
for (let i = 0; i < numExecutions; i++) {
let cursor = i == 0 ? '' : btoa(`next___${testCase.cars[testCase.query.limit * i].licensePlate}`);
let nextCursor = i < numExecutions - 1 ? btoa(`next___${testCase.cars[testCase.query.limit * i + 1].licensePlate}`) : '';
Expand Down

0 comments on commit 9633aeb

Please sign in to comment.