"use strict";

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

var _bn = _interopRequireDefault(require("bn.js"));

var _Date = _interopRequireDefault(require("./Date"));

var _U = _interopRequireDefault(require("../primitive/U64"));

// Copyright 2017-2019 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
describe('Date', () => {
  describe('decode', () => {
    const testDecode = function testDecode(type, input, expected) {
      let toJSON = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
      return it("can decode from ".concat(type), () => {
        expect(new _Date.default(input)[toJSON ? 'toJSON' : 'toISOString']()).toBe(expected);
      });
    };

    testDecode('Date', new Date(1537968546280), '2018-09-26T13:29:06.280Z');
    testDecode('CodecDate', new _Date.default(1234), 1234, true);
    testDecode('number', 1234, 1234, true);
    testDecode('U64', new _U.default(69), 69, true);
  });
  describe('encode', () => {
    const testEncode = (to, expected) => it("can encode ".concat(to), () => {
      expect(new _Date.default(421)[to]()).toEqual(expected);
    });

    testEncode('toBn', new _bn.default(421));
    testEncode('toJSON', 421);
    testEncode('toISOString', '1970-01-01T00:07:01.000Z');
    testEncode('toNumber', 421);
    testEncode('toU8a', Uint8Array.from([165, 1, 0, 0, 0, 0, 0, 0]));
    it('can encode toString', () => {
      expect(new _Date.default(421).toString().startsWith('Thu Jan 01 1970') // The time depends on the timezone this test is run in
      ).toBe(true);
    });
    it('encodes default BE hex', () => {
      expect(new _Date.default(3).toHex()).toEqual('0x0000000000000003');
    });
    it('encodes options LE hex', () => {
      expect(new _Date.default(3).toHex(true)).toEqual('0x0300000000000000');
    });
  });
  describe('utils', () => {
    it('compares values', () => {
      expect(new _Date.default(123).eq(123)).toBe(true);
    });
    it('compares values (non-match)', () => {
      expect(new _Date.default(123).eq(456)).toBe(false);
    });
  });
});