"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _immutable = require("immutable");

var _constants = require("@instructure/quiz-common/lib/constants");

var _recordTests = require("../../../../tests/util/recordTests");

var _QtiImport = _interopRequireDefault(require("../QtiImport"));

var _Bank = _interopRequireDefault(require("../Bank"));

describe('Bank record', function () {
  it('converts string timestamps to Date', function () {
    var bank = new _Bank.default({
      createdAt: '2017-02-12T17:36:00.000Z',
      updatedAt: '2017-03-13T17:36:00.000Z'
    });
    expect(bank.createdAt()).to.eql(new Date('2017-02-12T17:36:00.000Z'));
    expect(bank.updatedAt()).to.eql(new Date('2017-03-13T17:36:00.000Z'));
  });
  it('uses default id to indicate not loaded', function () {
    expect(new _Bank.default().isLoaded()).to.eq(false);
    expect(new _Bank.default({
      id: 123
    }).isLoaded()).to.eq(true);
  });
  describe('#isTemporary', function () {
    it('returns true if temporary id', function () {
      expect(new _Bank.default({
        id: _constants.TEMPORARY_BANK_ID
      }).isTemporary()).to.be.true();
    });
  });
  describe('#canImport', function () {
    it('returns true if status is "waiting" and there are no bankEntries', function () {
      var bank = new _Bank.default({
        status: 'waiting',
        entryCount: 0,
        bankEntries: new Set()
      });
      expect(bank.canImport()).to.be.true();
    });
    it('returns false if status is not "waiting"', function () {
      var bank = new _Bank.default({
        status: 'importing',
        entryCount: 0,
        bankEntries: new Set()
      });
      expect(bank.canImport()).to.be.false();
    });
    it('returns false a bankEntry is associated to it', function () {
      var bank = new _Bank.default({
        status: 'waiting',
        entryCount: 1,
        bankEntries: new Set('1')
      });
      expect(bank.canImport()).to.be.false();
    });
  });
  describe('#getLatestImport', function () {
    var bankId = '2';
    var laterImportData = {
      parentId: bankId,
      parentType: 'Bank',
      id: '2'
    };
    var exampleState = {
      qtiImports: {
        1: {
          parentId: bankId,
          parentType: 'Bank',
          id: '1'
        },
        2: laterImportData
      }
    };
    var options = {
      RelationRecordType: _QtiImport.default,
      relationAttrs: laterImportData,
      recordAttributes: {
        id: bankId
      },
      necessaryState: (0, _immutable.fromJS)(exampleState)
    };
    (0, _recordTests.singleRelationCheck)(_Bank.default, 'getLatestImport', options);
  });
});