Your IP : 216.73.216.220


Current Path : /proc/thread-self/root/home/deltalab/PMS/partner-manager-backend/test/
Upload File :
Current File : //proc/thread-self/root/home/deltalab/PMS/partner-manager-backend/test/order.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 { productInventoryModel } = require("../models/mongoose/product");

// 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"
};

// TEST CASES ======================================

describe('orders', 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('sync orders', async function () {
    oms.checkOrders();
    console.log('>>>>> STEP 1 <<<<<<');
    oms.checkOrders();
    console.log('>>>>> STEP 2 <<<<<<');
    await oms.checkOrders();
    console.log('>>>>> finished! <<<<<<');
  });

  it('sync order', async function () {
    oms.checkOrder(myorder);
    console.log('>>>>> STEP 1 <<<<<<');
    oms.checkOrder(myorder);
    console.log('>>>>> STEP 2 <<<<<<');
    await oms.checkOrder(myorder);
    console.log('>>>>> finished! <<<<<<');
  });


  it('book quantities', async function () {
    console.log('start booking');
    await oms.bookQuantities(myorder);
    console.log('end booking');
  });

  

});