Skip to content

Instantly share code, notes, and snippets.

@eddwinpaz
Created March 17, 2020 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eddwinpaz/6e8cb3dc2e39e7048c3b420041aa20da to your computer and use it in GitHub Desktop.
Save eddwinpaz/6e8cb3dc2e39e7048c3b420041aa20da to your computer and use it in GitHub Desktop.
issue with fastify
/* order domain information mock (jest) */
const mock_order_domain_information = orderJSON(1);
/* Notification Request Body */
const request_notification_service = {
body: {
message: {
attributes: {
eventType: ORDER_CREATED,
entityId: "d151c52e-3ad1-11ea-b77f-2e728ce88125",
eventId: "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11",
country: "CL",
siteId: "123123123123213"
},
data: _extractDataParam
}
}
// params: {
// orderId: "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11"
// },
// headers: {
// "x-site-id": "NA"
// }
};
/* response */
const notification_service_response_valid = {
orderNumber: "2302768646",
orderTotal: "126980",
shipmentCost: "6990",
status: "CLOSED",
user: {
name: "claudia",
lastName: "morales",
email: "15176367-7@gmail.com",
phone: "56 972810799"
},
payments: [
{
method: "WEBPAY",
installmentsNumber: "6",
amount: "126980"
}
],
deliveryOrders: [
{
deliveryOrderLines: [
{
status: "DELIVERED",
itemName: "Comedor 4 sillas café",
offerId: "2720302",
variantId: "2720302",
itemQuantity: "1",
itemPrice: "119990",
subtotal: "119990",
salesUnit: "C/U",
services: {
itemName: "",
itemDescription: "",
itemPrice: "",
itemQuantity: ""
},
warranty: {
itemName: "",
itemDescription: "",
itemPrice: "",
itemQuantity: ""
}
},
{
status: "DELIVERED",
itemName: "Servicio de armado",
offerId: "2720303",
variantId: "2720303",
itemQuantity: "1",
itemPrice: "119990",
subtotal: "119990",
salesUnit: "C/U",
services: {
itemName: "",
itemDescription: "",
itemPrice: "",
itemQuantity: ""
},
warranty: {
itemName: "",
itemDescription: "",
itemPrice: "",
itemQuantity: ""
}
}
],
method: "Despacho a domicilio",
group: "1",
shipmentAddress: "calle assen 4405 jardines la floresta 5 .",
pickupPoint: {
storeName: "",
storeAddress: ""
},
pickupPersonName: "claudia",
pickupPersonPhone: "56 972810799",
deliveryDate: "2018-02-09T03:00:00Z",
deliveryHour: "09:00 - 21:00"
},
{
deliveryOrderLines: [
{
status: "DELIVERED",
itemName: "Mantel",
offerId: "2720304",
variantId: "2720304",
itemQuantity: "1",
itemPrice: "119990",
subtotal: "119990",
salesUnit: "C/U",
services: {
itemName: "",
itemDescription: "",
itemPrice: "",
itemQuantity: ""
},
warranty: {
itemName: "",
itemDescription: "",
itemPrice: "",
itemQuantity: ""
}
}
],
method: "Retiro en tienda",
group: "2",
shipmentAddress: "calle assen 4405 jardines la floresta 5 .",
pickupPoint: {
storeName: "",
storeAddress: ""
},
pickupPersonName: "claudia",
pickupPersonPhone: "56 972810799",
deliveryDate: "2018-02-09T03:00:00Z",
deliveryHour: "09:00 - 21:00"
}
]
};
/* TEST */
describe("Notification Services Test", () => {
let fastify;
beforeAll(async () => {
fastify = create();
await fastify.ready();
fastify.getAccessToken = jest.fn().mockResolvedValue("Bearer 12322");
fastify.getTenantId = jest.fn().mockResolvedValue("99d8dcc9-9914-4469-93ea-67b1797a2f12");
fastify.getTenantFromHeader = jest.fn().mockResolvedValue("CHILE");
});
afterAll(async () => {
jest.clearAllMocks();
await fastify.close();
});
test("notificationService returns valid response", async () => {
getOrderDomainInformation.mockResolvedValueOnce(mock_order_domain_information);
const result = await notificationService(fastify, notification_service_response_valid);
console.log("====== result. notification service =======");
console.log(result);
expect(result).toEqual(notification_service_response_valid);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment