Skip to content

Commit 8e1900e

Browse files
authored
Merge pull request #10 from catenax-ng/TRACEFOSS-986-notification-reason
TRACEFOSS-986: added reason visualisation for notification
2 parents 55f8d9a + 9716f5d commit 8e1900e

File tree

41 files changed

+741
-95
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+741
-95
lines changed

src/app/mocks/services/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
export { dashboardHandler } from './dashboard-mock/dashboard.handler';
2323
export { partsHandlers, partsHandlersTest } from './parts-mock/parts.handler';
2424
export { otherPartsHandlers, otherPartsHandlersTest } from './otherParts-mock/otherParts.handler';
25-
export { investigationsHandlers } from './investigations-mock/investigations.handler';
25+
export { investigationsHandlers, investigationsTestHandlers } from './investigations-mock/investigations.handler';
2626
export { adminHandler } from './admin-mock/admin.handler';
2727
export { errorHandler } from './error-mock/error.handler';

src/app/mocks/services/investigations-mock/investigations.handler.ts

Lines changed: 95 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,29 @@ import { NotificationStatus } from '@shared/model/notification.model';
2424
import { rest } from 'msw';
2525
import { applyPagination, extractPagination } from '../pagination.helper';
2626
import { buildMockInvestigations, getInvestigationById, InvestigationIdPrefix } from './investigations.model';
27+
import {
28+
buildMockInvestigations as testBuildMockInvestigations,
29+
getInvestigationById as testGetInvestigationById,
30+
InvestigationIdPrefix as testInvestigationIdPrefix,
31+
} from './investigations.test.model';
32+
33+
const commonHandler = [
34+
rest.post(`*${environment.apiUrl}/investigations/:investigationId/close`, (req, res, ctx) => {
35+
return res(ctx.status(204));
36+
}),
37+
38+
rest.post(`*${environment.apiUrl}/investigations/:investigationId/approve`, (req, res, ctx) => {
39+
return res(ctx.status(204));
40+
}),
41+
42+
rest.post(`*${environment.apiUrl}/investigations/:investigationId/cancel`, (req, res, ctx) => {
43+
return res(ctx.status(204));
44+
}),
45+
46+
rest.post(`${environment.apiUrl}/investigations/:investigationId/update`, (req, res, ctx) => {
47+
return res(ctx.status(204));
48+
}),
49+
];
2750

2851
export const investigationsHandlers = [
2952
rest.get(`*${environment.apiUrl}/investigations/created`, (req, res, ctx) => {
@@ -35,6 +58,8 @@ export const investigationsHandlers = [
3558
NotificationStatus.ACKNOWLEDGED,
3659
NotificationStatus.ACCEPTED,
3760
NotificationStatus.DECLINED,
61+
NotificationStatus.CLOSED,
62+
NotificationStatus.CANCELED,
3863
];
3964

4065
return res(
@@ -46,7 +71,14 @@ export const investigationsHandlers = [
4671
rest.get(`*${environment.apiUrl}/investigations/received`, (req, res, ctx) => {
4772
const pagination = extractPagination(req);
4873

49-
const currentStatus = [NotificationStatus.RECEIVED, NotificationStatus.ACKNOWLEDGED];
74+
const currentStatus = [
75+
NotificationStatus.RECEIVED,
76+
NotificationStatus.ACKNOWLEDGED,
77+
NotificationStatus.ACCEPTED,
78+
NotificationStatus.DECLINED,
79+
NotificationStatus.CLOSED,
80+
NotificationStatus.CANCELED,
81+
];
5082
return res(
5183
ctx.status(200),
5284
ctx.json(applyPagination(buildMockInvestigations(currentStatus, 'RECEIVER'), pagination)),
@@ -67,14 +99,18 @@ export const investigationsHandlers = [
6799
NotificationStatus.ACKNOWLEDGED,
68100
NotificationStatus.ACCEPTED,
69101
NotificationStatus.DECLINED,
102+
70103
NotificationStatus.ACKNOWLEDGED,
104+
NotificationStatus.ACCEPTED,
105+
NotificationStatus.DECLINED,
106+
NotificationStatus.CLOSED,
107+
NotificationStatus.CANCELED,
71108
];
72-
const channel = indexFromId === 2 || indexFromId === 8 ? 'RECEIVER' : 'SENDER';
109+
const channel = [2, 8, 9, 10, 11, 12].includes(indexFromId) ? 'RECEIVER' : 'SENDER';
73110
const randomNotification = buildMockInvestigations([statusCollection[indexFromId]], channel)[0];
74111

75112
return res(ctx.status(200), ctx.json({ ...randomNotification, id: investigationId }));
76113
}),
77-
78114
rest.post(`*${environment.apiUrl}/investigations`, (_, res, ctx) => {
79115
return res(ctx.status(200), ctx.json({ id: InvestigationIdPrefix + 1 }));
80116
}),
@@ -86,20 +122,68 @@ export const investigationsHandlers = [
86122
const investigation = getInvestigationById(investigationId as string);
87123
return res(ctx.status(200), ctx.json({ ...investigation, status }));
88124
}),
125+
...commonHandler,
126+
];
89127

90-
rest.post(`*${environment.apiUrl}/investigations/:investigationId/close`, (req, res, ctx) => {
91-
return res(ctx.status(204));
128+
export const investigationsTestHandlers = [
129+
rest.get(`*${environment.apiUrl}/investigations/created`, (req, res, ctx) => {
130+
const pagination = extractPagination(req);
131+
132+
const currentStatus = [
133+
NotificationStatus.CREATED,
134+
NotificationStatus.APPROVED,
135+
NotificationStatus.ACKNOWLEDGED,
136+
NotificationStatus.ACCEPTED,
137+
NotificationStatus.DECLINED,
138+
];
139+
140+
return res(
141+
ctx.status(200),
142+
ctx.json(applyPagination(testBuildMockInvestigations(currentStatus, 'SENDER'), pagination)),
143+
);
92144
}),
93145

94-
rest.post(`*${environment.apiUrl}/investigations/:investigationId/approve`, (req, res, ctx) => {
95-
return res(ctx.status(204));
146+
rest.get(`*${environment.apiUrl}/investigations/received`, (req, res, ctx) => {
147+
const pagination = extractPagination(req);
148+
149+
const currentStatus = [NotificationStatus.RECEIVED, NotificationStatus.ACKNOWLEDGED];
150+
return res(
151+
ctx.status(200),
152+
ctx.json(applyPagination(testBuildMockInvestigations(currentStatus, 'RECEIVER'), pagination)),
153+
);
96154
}),
97155

98-
rest.post(`*${environment.apiUrl}/investigations/:investigationId/cancel`, (req, res, ctx) => {
99-
return res(ctx.status(204));
156+
rest.get(`*${environment.apiUrl}/investigations/:investigationId`, (req, res, ctx) => {
157+
const { investigationId } = req.params;
158+
159+
const indexFromId = parseInt((investigationId as string).replace('id-', ''), 10);
160+
161+
const statusCollection = [
162+
NotificationStatus.CREATED,
163+
NotificationStatus.APPROVED,
164+
NotificationStatus.RECEIVED,
165+
NotificationStatus.CLOSED,
166+
NotificationStatus.CANCELED,
167+
NotificationStatus.ACKNOWLEDGED,
168+
NotificationStatus.ACCEPTED,
169+
NotificationStatus.DECLINED,
170+
NotificationStatus.ACKNOWLEDGED,
171+
];
172+
const channel = indexFromId === 2 || indexFromId === 8 ? 'RECEIVER' : 'SENDER';
173+
const randomNotification = testBuildMockInvestigations([statusCollection[indexFromId]], channel)[0];
174+
175+
return res(ctx.status(200), ctx.json({ ...randomNotification, id: investigationId }));
176+
}),
177+
rest.post(`*${environment.apiUrl}/investigations`, (_, res, ctx) => {
178+
return res(ctx.status(200), ctx.json({ id: testInvestigationIdPrefix + 1 }));
100179
}),
101180

102-
rest.post(`${environment.apiUrl}/investigations/:investigationId/update`, (req, res, ctx) => {
103-
return res(ctx.status(204));
181+
rest.put(`*${environment.apiUrl}/investigations/:investigationId/status`, (req, res, ctx) => {
182+
const { investigationId } = req.params;
183+
const { status } = req.body as Record<string, unknown>;
184+
185+
const investigation = testGetInvestigationById(investigationId as string);
186+
return res(ctx.status(200), ctx.json({ ...investigation, status }));
104187
}),
188+
...commonHandler,
105189
];

src/app/mocks/services/investigations-mock/investigations.model.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import type { NotificationResponse } from '@shared/model/notification.model';
2323
import { NotificationStatus } from '@shared/model/notification.model';
2424
import { getRandomAsset } from '../parts-mock/parts.model';
2525
import { MOCK_part_1 } from '../parts-mock/parts.test.model';
26+
import { getRandomIntFromInterval, getRandomText } from '../text-generator.helper';
2627

2728
export const InvestigationIdPrefix = 'id-';
2829
export const buildMockInvestigations = (
@@ -31,12 +32,28 @@ export const buildMockInvestigations = (
3132
): NotificationResponse[] =>
3233
new Array(25).fill(null).map((_, index) => {
3334
const status = statuses[index % statuses.length];
35+
36+
const close = status === NotificationStatus.CLOSED ? getRandomText(getRandomIntFromInterval(15, 500)) : '';
37+
const isDeclined = Math.random() >= 0.5;
38+
39+
const decline =
40+
status === NotificationStatus.DECLINED || (!!close && isDeclined)
41+
? getRandomText(getRandomIntFromInterval(15, 500))
42+
: '';
43+
44+
const accept =
45+
status === NotificationStatus.ACCEPTED || (!!close && !isDeclined)
46+
? getRandomText(getRandomIntFromInterval(15, 500))
47+
: '';
48+
3449
return {
3550
id: `${InvestigationIdPrefix}${index + 1}`,
36-
description: `Investigation No ${index + 1}`,
51+
description: `Investigation No ${index + 1} ${getRandomText(getRandomIntFromInterval(15, 500))}`,
3752
status,
3853
channel,
39-
createdBy: 'BPNL00000003AYRE',
54+
createdBy: 'OEM A',
55+
sendTo: 'OEM B',
56+
reason: { close, decline, accept },
4057
createdDate: `2022-05-${(index + 1).toString().padStart(2, '0')}T12:34:12`,
4158
assetIds: [MOCK_part_1.id, getRandomAsset().id, getRandomAsset().id, getRandomAsset().id],
4259
};
@@ -47,6 +64,8 @@ const MockEmptyInvestigation: NotificationResponse = {
4764
description: `Investigation No 000`,
4865
status: NotificationStatus.CREATED,
4966
createdBy: 'OEM A',
67+
sendTo: 'OEM B',
68+
reason: { close: '', decline: '', accept: '' },
5069
createdDate: `2022-05-01T12:34:12`,
5170
assetIds: [getRandomAsset().id],
5271
channel: 'SENDER',
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/********************************************************************************
2+
* Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
3+
* Copyright (c) 2022, 2023 ZF Friedrichshafen AG
4+
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
5+
*
6+
* See the NOTICE file(s) distributed with this work for additional
7+
* information regarding copyright ownership.
8+
*
9+
* This program and the accompanying materials are made available under the
10+
* terms of the Apache License, Version 2.0 which is available at
11+
* https://www.apache.org/licenses/LICENSE-2.0.
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
* SPDX-License-Identifier: Apache-2.0
20+
********************************************************************************/
21+
22+
import type { NotificationResponse } from '@shared/model/notification.model';
23+
import { NotificationStatus } from '@shared/model/notification.model';
24+
import { getRandomAsset } from '../parts-mock/parts.model';
25+
import { MOCK_part_1 } from '../parts-mock/parts.test.model';
26+
27+
export const InvestigationIdPrefix = 'id-';
28+
export const buildMockInvestigations = (
29+
statuses: NotificationStatus[],
30+
channel: 'SENDER' | 'RECEIVER',
31+
): NotificationResponse[] =>
32+
new Array(25).fill(null).map((_, index) => {
33+
const status = statuses[index % statuses.length];
34+
return {
35+
id: `${InvestigationIdPrefix}${index + 1}`,
36+
description: `Investigation No ${index + 1}`,
37+
status,
38+
channel,
39+
createdBy: 'OEAM A',
40+
sendTo: 'OEM B',
41+
reason: { close: '', accept: '', decline: '' },
42+
createdDate: `2022-05-${(index + 1).toString().padStart(2, '0')}T12:34:12`,
43+
assetIds: [MOCK_part_1.id, getRandomAsset().id, getRandomAsset().id, getRandomAsset().id],
44+
};
45+
});
46+
47+
const MockEmptyInvestigation: NotificationResponse = {
48+
id: `${InvestigationIdPrefix}000`,
49+
description: `Investigation No 000`,
50+
status: NotificationStatus.CREATED,
51+
createdBy: 'OEM A',
52+
sendTo: 'OEAM B',
53+
reason: { close: '', accept: '', decline: '' },
54+
createdDate: `2022-05-01T12:34:12`,
55+
assetIds: [getRandomAsset().id],
56+
channel: 'SENDER',
57+
};
58+
59+
export const getInvestigationById = (id: string) => {
60+
return [].find(investigation => investigation.id === id) || { ...MockEmptyInvestigation, id };
61+
};

0 commit comments

Comments
 (0)