| Current Path : /home/deltalab/PMS/partner-manager-backend/test/ |
| Current File : //home/deltalab/PMS/partner-manager-backend/test/shipment.test.js |
/**
* Shipment tests, creation, control and monitoring.
*/
// DEPENDENCIES ====================================
const { expect, assert } = require ('chai');
const { dotenv } = require ('dotenv').config();
const mongoose = require ('mongoose');
// RESOURCES =======================================
const oms = require ('../services/oms');
const sms = require ('../services/sms');
const { orderModel } = require ("../models/mongoose/order");
// TEST OBJECTS ====================================
// OMS order to be checked for
// this order data is meant to be received by the OMS
// either by polling or by webhook
const myorder = {
items: [
// {
// name : "Example T-Shirt - Lithograph - Height: 9\" x Width: 12\"",
// imsgid : "gid://shopify/Product/6734691500208",
// sku : "1612xxx",
// quantity : 1,
// totalPriceSet : {
// amount : 25,
// currencyCode : "EUR"
// },
// unitPriceSet : {
// amount : 25,
// currencyCode : "EUR"
// },
// },
// {
// name : "pms 0120b",
// imsgid : "gid://shopify/Product/7027111198896",
// sku : "0120b",
// quantity : 20,
// totalPriceSet : {
// amount : 25,
// currencyCode : "EUR"
// },
// unitPriceSet : {
// amount : 25,
// currencyCode : "EUR"
// },
{
name: "Prodotto da magazzino con tante mail",
imsgid: "gid://shopify/Product/7038210146480",
sku: "1612xxx",
quantity: 1,
totalPriceSet: {
amount: 111,
currencyCode: "EUR"
},
unitPriceSet: {
amount: 111,
currencyCode: "EUR"
},
},
],
omsgid: "gid://shopify/Order/3882359750832",
name: "#1006",
createdAt: "2021-07-01T13:21:49.000Z", //ISODate
customer: {
displayName: "Daniele Dellagiacoma",
phone: "+393493408911",
email: "deltalab@deltainformatica.eu"
},
shippingAddress: {
name: "Daniele Dellagiacoma",
company: "",
address1: "via del Revì, 24",
address2: "",
city: "Aldeno",
province: "TN",
state: "Italy",
zip: "38060",
country: "Italy",
email: "deltalab@deltainformatica.eu",
phone: "+393493408911"
},
totalPriceSet: {
amount: 34.99,
currencyCode: "EUR"
},
//status : "Fulfilled",
status: "Processing",
partnerId: "6125199597b1612d8071eafd",
updatedAt: "2021-11-05T17:18:52.452Z", //ISODate
shipmentId: "6185677cddc25834befa82eb"
};
const mywarehouse = {
carrier: { smsid: '2861', name: 'Generic', service: 'Standard' },
rate: 0,
rateId: '16445883272674',
deliveryDays: '1-10',
currency: 'EUR',
warehouse: {
_id: "61e92584faf525e7124eb0ce",
name: 'Megazzino Delta',
address: {
name: 'Sede centrale',
latitude: null,
longitude: null,
company: 'Newco Srl',
street1: 'Via Kufstein, 5',
street2: '',
city: 'Trento',
province: 'TN',
state: '',
zip: '38121',
country: 'Italy',
phone: '0461225589',
email: 'andrea.gottardi@deltainformatica.eu'
},
email: [ 'info@deltainformatica.eu' ],
phone: '0461422000',
partnerId: "6125199597b1612d8071eafd",
createdAt: "2022-01-20T09:04:04.231Z",
updatedAt: "2022-02-01T15:26:23.378Z"
},
from: {
name: 'Sede centrale',
company: 'Newco Srl',
street1: 'Via Kufstein, 5',
street2: '',
city: 'Trento',
state: 'Italy',
zip: '38121',
country: 'IT',
phone: '0461225589',
email: 'andrea.gottardi@deltainformatica.eu'
}
}
// TEST CASES ======================================
describe ('shipments', function () {
this.timeout(15000);
// Initialization --------------------------------
before((done) => {
mongoose.connect(process.env.database_url);
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error'));
db.once('open', function() {
console.log('We are connected to test database!');
done();
});
});
let orderId; // the id of the created order
it ('filter by partner', async function () {
const partnerId = "6125199597b1612d8071eafd";
const orders = await orderModel.find({ partnerId: partnerId});
console.log(orders);
});
it ('checkOrder', (done) => {
console.log("checking if an order exists");
// Start the order processing
oms.checkOrder(myorder)
.then((orderCheck) =>
{
orderId = orderCheck.order._id;
console.log(orderCheck);
done();
})
.catch(done);
});
it ('deleteOrder', (done) => {
// this is basically used to clean up the mess
console.log(`remove the order ${orderId}`);
orderModel.deleteOne( { _id: mongoose.Types.ObjectId(orderId) })
.then((order) => {
console.log(`order ${order} deleted`);
//TODO: remove the shipment in cascade
done();
})
.catch(done);
});
it('pick quantities', async function () {
console.log('start picking');
await sms.pickQuantities(myorder, mywarehouse);
console.log('end picking');
});
});