| Current Path : /home/deltalab/PMS/partner-manager-backend/test/ |
| Current File : //home/deltalab/PMS/partner-manager-backend/test/invoice.test.js |
/**
* This is a simple test example.
*
* You can use this as a template for other examples
*/
// DEPENDENCIES ====================================
const { expect, assert } = require ('chai');
const { dotenv } = require ('dotenv').config();
const mongoose = require ('mongoose');
// RESOURCES =======================================
const { invoiceModel } = require ('../models/mongoose/invoice');
const { orderModel } = require ('../models/mongoose/order');
const billing = require ('../services/billing')
// TEST CASES ======================================
let userId;
describe ('invoice', () => {
// 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();
});
});
it ('Create and persist an Invoice', async () => {
const invoice = await billing.createInvoice("61bb4e8e2bdd0db62eb77b4b", new Date(2021,10,1), new Date(2021,11,1));
console.log(invoice);
console.log(invoice.servicesTotal);
console.log(invoice.royaltiesTotal);
console.log(invoice.ordersTotal);
const savedInvoice = await invoice.save();
expect(invoice.orders.length).to.eq(savedInvoice.orders.length);
});
it ('filter by partner', async function () {
const partnerId = "61bb4e8e2bdd0db62eb77b4b";
const orders = await orderModel.find({ partnerId: partnerId});
console.log(orders);
});
});