Skip to content

Commit

Permalink
[MS] Adds API and mocks for custom order requests list
Browse files Browse the repository at this point in the history
  • Loading branch information
Max-7 authored and fabienSvstr committed Dec 26, 2024
1 parent 4da3f0d commit 865ef60
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 2 deletions.
30 changes: 29 additions & 1 deletion client/src/services/bms/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,13 +692,40 @@ async function createCustomOrderRequest(token: AuthenticationToken, query: Creat
},
);
return {
type: DataType.CreateCustomOrderRequest,
status: axiosResponse.status,
isError: false,
};
});
}

async function getCustomOrderRequests(token: AuthenticationToken): Promise<BmsResponse> {
return wrapQuery(async () => {
const axiosResponse = await http.getInstance().get('/custom_order_requests', {
headers: { Authorization: `Bearer ${token}` },
validateStatus: (status) => status === 200,
});

return {
status: axiosResponse.status,
isError: false,
data: {
type: DataType.GetCustomOrderRequests,
requests: axiosResponse.data.requests.map((req: any) => {
return {
id: req.id,
describedNeeds: req.described_need,
users: req.standard_users,
storage: req.storage,
status: req.status,
comment: req.comment,
orderDate: DateTime.fromISO(axiosResponse.data.created_at),
};
}),
},
};
});
}

export const BmsApi = {
login,
getPersonalInformation,
Expand All @@ -723,4 +750,5 @@ export const BmsApi = {
subscribeOrganization,
updateEmailSendCode,
createCustomOrderRequest,
getCustomOrderRequests,
};
54 changes: 54 additions & 0 deletions client/src/services/bms/mockApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ClientQueryData,
CreateCustomOrderRequestQueryData,
CustomOrderQueryData,
CustomOrderRequestStatus,
CustomOrderStatus,
DataType,
InvoiceStatus,
Expand Down Expand Up @@ -212,4 +213,57 @@ export const MockedBmsApi = {
};
},
),
getCustomOrderRequests: createMockFunction(
'getCustomOrderRequests',
async (_token: AuthenticationToken) => {
return {
status: 200,
isError: false,
requests: [
{
id: 'XX-1',
describedNeeds: 'I wanna rock!',
users: 50,
storage: 1000,
status: CustomOrderRequestStatus.Processing,
comment: 'Turn it down you say, nut all I got to say to you is time and time again I say no (no), no no, no no, no.',
orderDate: DateTime.now().minus({ months: 2 }),
},
{
id: 'XX-2',
describedNeeds: 'I want to hold your hand',
users: 50,
storage: 1000,
status: CustomOrderRequestStatus.Received,
comment: "I think you'll understand",
orderDate: DateTime.now().minus({ days: 4 }),
},
{
id: 'XX-3',
describedNeeds: 'I want to break free!',
users: 300,
storage: 9999,
status: CustomOrderRequestStatus.Finished,
comment: "I've fallen in love",
orderDate: DateTime.now().minus({ months: 6 }),
},
{
id: 'XX-4',
describedNeeds: 'I want you to want me',
users: 9999,
storage: 100,
status: CustomOrderRequestStatus.Cancelled,
comment: 'I need you to need me',
orderDate: DateTime.now().minus({ days: 6 }),
},
],
};
},
async (_token: AuthenticationToken) => {
return {
status: 401,
isError: true,
};
},
),
};
26 changes: 25 additions & 1 deletion client/src/services/bms/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enum DataType {
CustomOrderStatus = 'custom-order-status',
CustomOrderDetails = 'custom-order-details',
CreateCustomOrderRequest = 'create-custom-order-request',
GetCustomOrderRequests = 'get-custom-order-requests',
}

enum PaymentMethod {
Expand All @@ -64,6 +65,14 @@ enum CustomOrderStatus {
InvoicePaid = 'invoice_paid',
}

enum CustomOrderRequestStatus {
Received = 'RECEIVED',
Processing = 'PROCESSING',
Standby = 'STANDBY',
Finished = 'FINISHED',
Cancelled = 'CANCELLED',
}

type AuthenticationToken = string;

// Data used for result
Expand Down Expand Up @@ -169,6 +178,19 @@ interface RefreshTokenResultData {
token: AuthenticationToken;
}

interface GetCustomOrderRequestsResultData {
type: DataType.GetCustomOrderRequests;
requests: {
id: string;
describedNeeds: string;
users: number;
storage: number;
status: CustomOrderRequestStatus;
comment: string;
orderDate: DateTime;
};
}

interface BmsAddress {
line1: string;
line2?: string;
Expand Down Expand Up @@ -215,7 +237,8 @@ type ResultData =
| RefreshTokenResultData
| BillingDetailsResultData
| CustomOrderStatusResultData
| CustomOrderDetailsResultData;
| CustomOrderDetailsResultData
| GetCustomOrderRequestsResultData;

// Misc data
interface BmsOrganization {
Expand Down Expand Up @@ -351,6 +374,7 @@ export {
CreateOrganizationQueryData,
CustomOrderDetailsResultData,
CustomOrderQueryData,
CustomOrderRequestStatus,
CustomOrderStatus,
CustomOrderStatusResultData,
DataType,
Expand Down
31 changes: 31 additions & 0 deletions client/tests/e2e/helpers/bms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,36 @@ async function mockCreateCustomOrderRequest(page: Page, options?: MockRouteOptio
});
}

async function mockGetCustomOrderRequests(page: Page, options?: MockRouteOptions): Promise<void> {
await mockRoute(page, '**/custom_order_requests', options, async (route) => {
await route.fulfill({
status: 200,
json: {
requests: [
{
id: 'YY-00001',
described_need: 'I need a hero!',
standard_users: 300,
storage: 1000,
status: 'STANDBY',
comment: "I'm holding out for a hero 'till the end of the night",
created_at: '1988-04-07T00:00:00+00:00',
},
{
id: 'YY-00002',
described_need: 'I need your love!',
standard_users: 9999,
storage: 9999,
status: 'FINISHED',
comment: 'I want you every way',
created_at: '1990-03-30T00:00:00+00:00',
},
],
},
});
});
}

export const MockBms = {
mockLogin,
mockUserRoute,
Expand All @@ -636,4 +666,5 @@ export const MockBms = {
mockCustomOrderDetails,
mockUpdateEmailSendCode,
mockCreateCustomOrderRequest,
mockGetCustomOrderRequests,
};

0 comments on commit 865ef60

Please sign in to comment.