"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const sinon_1 = __importDefault(require("sinon"));
const internal_1 = require("../../../internal");
const types_1 = require("../../../types");
const utilsInternalModule = __importStar(require("../../../utils/internal"));
// eslint-disable-next-line require-jsdoc
class NonAbstract extends internal_1.Entity {
    // eslint-disable-next-line require-jsdoc
    toJson() {
        return true;
    }
    // eslint-disable-next-line require-jsdoc
    exists() {
        return __awaiter(this, void 0, void 0, function* () {
            return true;
        });
    }
}
describe('Entity class', () => {
    afterAll(() => {
        sinon_1.default.restore();
    });
    const serializeStub = sinon_1.default.stub(utilsInternalModule, 'serialize');
    describe('method: generateUuid', () => {
        test("should generate the Entity's UUID", () => __awaiter(void 0, void 0, void 0, function* () {
            serializeStub
                .withArgs('Entity', {
                did: 'abc',
            })
                .returns('uuid');
            const result = internal_1.Entity.generateUuid({ did: 'abc' });
            expect(result).toBe('uuid');
        }));
    });
    describe('method: unserialize', () => {
        let unserializeStub;
        beforeAll(() => {
            unserializeStub = sinon_1.default.stub(utilsInternalModule, 'unserialize');
        });
        test('should throw an error if the string is not related to an Entity Unique Identifier', () => __awaiter(void 0, void 0, void 0, function* () {
            unserializeStub.returns(undefined);
            expect(() => internal_1.Entity.unserialize('def')).toThrow("The string doesn't correspond to the UUID of type Entity");
        }));
        test('should return an Entity Unique Identifier object', () => __awaiter(void 0, void 0, void 0, function* () {
            const fakeReturn = { someIdentifier: 'abc' };
            unserializeStub.returns(fakeReturn);
            expect(internal_1.Entity.unserialize('def')).toEqual(fakeReturn);
        }));
    });
    describe('method: isEqual', () => {
        test('should return whether the entities are the same', () => {
            serializeStub.withArgs('NonAbstract', { foo: 'bar' }).returns('first');
            serializeStub.withArgs('NonAbstract', { bar: 'baz' }).returns('second');
            const first = new NonAbstract({ foo: 'bar' }, {});
            const second = new NonAbstract({ bar: 'baz' }, {});
            expect(first.isEqual(first)).toBe(true);
            expect(first.isEqual(second)).toBe(false);
            expect(second.isEqual(first)).toBe(false);
        });
    });
});
describe('isEntity', () => {
    afterAll(() => {
        sinon_1.default.restore();
    });
    test('should return whether the value is an Entity', () => {
        const serializeStub = sinon_1.default.stub(utilsInternalModule, 'serialize');
        serializeStub.withArgs('NonAbstract', { foo: 'bar' }).returns('uuid');
        const entity = new NonAbstract({ foo: 'bar' }, {});
        expect(types_1.isEntity(entity)).toBe(true);
    });
});
//# sourceMappingURL=Entity.js.map