"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
var _require = require('bson'),
  ObjectId = _require.ObjectId;
var Container = require('./container');
describe('Container', function () {
  var container = new Container();
  it('should return null normalize values if no units are passed in', function () {
    expect(container.normalizeSizeAndAmount(1, 1, null).normalizedSize).toEqual({
      gram: null,
      liter: null
    });
  });
  it('should return null normalize values if unit isother ', function () {
    expect(container.normalizeSizeAndAmount(1, 1, 'other').normalizedSize).toEqual({
      gram: null,
      liter: null
    });
  });
  it('should normalize to gram using conversion factory', function () {
    expect(container.normalizeSizeAndAmount(2, 1, 'μg').normalizedSize).toEqual({
      gram: 0.000002,
      liter: 2e-9
    });
  });
  it('should normalize units gram using density when unit is volume', function () {
    expect(container.normalizeSizeAndAmount(2, 1, 'μL', '.5').normalizedSize).toEqual({
      gram: 0.001,
      liter: 0.000002
    });
  });
  it('should normalize units gram defaulting density to 1 when density is not supplied when unit is volume', function () {
    expect(container.normalizeSizeAndAmount(2, 1, 'μL').normalizedSize).toEqual({
      gram: 0.002,
      liter: 0.000002
    });
  });
  it('should set container amount to container size if not passed in', function () {
    var cont = new Container({
      size: 10,
      amount: null
    });
    expect(cont.amount).toEqual(10);
  });
  it('should allow container amount to be zero', function () {
    var cont = new Container({
      amount: 0,
      size: 10
    });
    expect(cont.amount).toEqual(0);
  });
  describe('barcode', function () {
    var containerData = {
      _id: new ObjectId('5abc0aca8bdad56d036adf48'),
      substance: {
        _id: null
      },
      family: {
        _id: new ObjectId('5956e591bd74595f951d41bf'),
        density: {
          value: 0.71,
          unit: 'g/mL'
        }
      },
      inventory: {
        _id: new ObjectId('5adf97597ed8203054035908'),
        tenantCode: 'UC',
        campusCode: '03',
        name: 'Demo Lab'
      },
      location: {
        buildingId: 'MDN8RFYtMDEtMDAxMjMw',
        floorId: 'MDN8RFYtMDEtMDAxMjMwfERWLTAxLTAwMDE3NjQ',
        roomId: 'MDN8RFYtMDEtMDAxMjMwfERWLTAxLTAwMDE3NjR8RFYtMDEtMDAwMzUzMTI',
        sublocationId: '5adfab3949a95f33e82afe04',
        buildingName: '',
        floorName: '',
        roomNumber: '',
        sublocationName: 'Davis 202 Cousteau Place - 205100'
      },
      size: 3,
      units: 'g',
      physicalState: 'Liquid',
      type: 'GLASS_BOTTLE',
      openedDate: null,
      receivedDate: null,
      expirationDate: null,
      lastTestedDate: null,
      isPrivate: false,
      barcode: 'UC0000241146',
      customBarcode: null,
      audits: [],
      tags: [],
      comments: null,
      checkout: null,
      normalized: {
        gram: 3,
        liter: 0.004225352112676057
      },
      solvent: null,
      concentration: null,
      concentrationUnits: null,
      createdByUserId: 'ian',
      _createdDate: new Date()
    };
    it('should validate UC barcode ', function () {
      var containerToValidate = new Container(containerData);
      var validation = containerToValidate.validate();
      expect(validation.valid).toBeTruthy();
    });
    it('should invalidate non-UC barcode ', function () {
      var containerToValidate = new Container(_objectSpread(_objectSpread({}, containerData), {}, {
        barcode: '99'
      }));
      var validation = containerToValidate.validate();
      expect(validation.valid).toBeFalsy();
    });
  });
});