Repository navigation
Expand file tree
/
Copy pathAppService.js
More file actions
97 lines (90 loc) · 2.43 KB
/
Copy pathAppService.js
File metadata and controls
97 lines (90 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const axios = require('axios');
class AppService {
orderToJob(order) {
return {
job: {
pickups: [
{
address: order.package.collect_task.address.street_name,
},
],
dropoffs: [
{
client_reference: order.package.reference,
package_type: order.package.dimensions.size,
address: order.package.deliver_task.address.street_name,
contact: {
contact_phone: order.package.dimensions.size,
},
},
],
},
};
}
async createJobDelay({ job }) {
const { HTTP_DELAY_IN_SECONDS = 2 } = process.env;
const { data } = await axios.get(
`https://httpbin.org/delay/${HTTP_DELAY_IN_SECONDS}`,
);
return this.createJob({ job });
}
async createJobRandomDelay({ job }) {
try {
const { data } = await axios.get(
'https://dummy-api.beta.stuart-apps.solutions/api/foo/bar',
);
return this.createJob({ job });
} catch (error) {
// We don't want to polute the performance test if the dummy service fails, so we just return the expected response.
console.error(error.message);
return this.createJob({ job });
}
}
async createJob({ job }) {
const dropoff = job.dropoffs[0];
const pickup = job.pickups[0];
return {
id: 100432273,
status: 'in_progress',
package_type: dropoff.package_type,
pickup_at: '2023-01-25T12:52:00.000+01:00',
deliveries: [
{
id: 100515659,
status: 'waiting_at_dropoff',
picked_at: '2023-01-25T12:50:34.000+01:00',
delivered_at: null,
client_reference: dropoff.client_reference,
package_description: null,
package_type: dropoff.package_type,
pickup: {
id: 2598682,
address: {
street: pickup.address,
},
},
dropoff: {
id: 2598683,
address: {
street: dropoff.address,
},
contact: {
phone: dropoff.contact.contact_phone,
company_name: null,
email: null,
},
},
},
],
};
}
jobToOrder(jobResponse) {
const delivery = jobResponse.deliveries[0];
return {
package: {
reference: delivery.client_reference,
},
};
}
}
module.exports = { AppService };