UNPKG

opencart-manager

Version:

Node.js package helping to manage your opencart store data easily.

71 lines (70 loc) 3.96 kB
"use strict"; 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 database_1 = __importDefault(require("../__mocks__/database")); const entity_1 = __importDefault(require("../__mocks__/entity")); const product_option_value_1 = __importDefault(require("../entities/product-option-value")); const initial_1 = require("../initial"); const model_1 = __importDefault(require("../model")); const product_option_value_2 = __importDefault(require("./product-option-value")); const productOptionValueId = 12; const productOptionId = 123; const optionValueId = 134; const entityRowsData = [ Object.assign(Object.assign({}, initial_1.initialProductOptionValue), { productOptionValueId, productOptionId, optionValueId, price: 123 }), ]; jest.mock("../entities/product-option-value", () => ({ __esModule: true, default: jest.fn((model, ...dependencies) => new entity_1.default(model, ...dependencies)), })); const database = new database_1.default(); const model = new model_1.default(database); model.product.option.value.select = jest.fn(() => __awaiter(void 0, void 0, void 0, function* () { return entityRowsData; })); const factory = new product_option_value_2.default(model); test("creates a new entity", () => { const entity = factory.create({ id: productOptionId }, { id: optionValueId }); expect(entity).toBeInstanceOf(entity_1.default); }); test("extracts and returns an entity", () => __awaiter(void 0, void 0, void 0, function* () { const entity = yield factory.extract({ productOptionValueId }); expect(entity).toBeInstanceOf(entity_1.default); expect(model.product.option.value.select).toHaveBeenNthCalledWith(1, { productOptionValueId, }); expect(product_option_value_1.default).toHaveBeenNthCalledWith(2, model, productOptionId, optionValueId, productOptionValueId); expect(entity.data.price).toBe(123); })); test("extracts all and returns an entities array", () => __awaiter(void 0, void 0, void 0, function* () { const entities = yield factory.extractAll({ productOptionValueId }); expect(entities).toBeArray(); const entity = entities[0]; expect(entity).toBeInstanceOf(entity_1.default); expect(model.product.option.value.select).toHaveBeenNthCalledWith(2, { productOptionValueId, }); expect(product_option_value_1.default).toHaveBeenNthCalledWith(3, model, productOptionId, optionValueId, productOptionValueId); expect(entity.data.price).toBe(123); })); test("extracts and returns an undefined", () => __awaiter(void 0, void 0, void 0, function* () { model.product.option.value.select = jest.fn(() => __awaiter(void 0, void 0, void 0, function* () { return []; })); const entity = yield factory.extract({ productOptionValueId: 9999 }); expect(entity).toBeUndefined(); })); test("extracts all and returns an empty array", () => __awaiter(void 0, void 0, void 0, function* () { const entities = yield factory.extractAll({ productOptionValueId: 9999 }); expect(entities).toBeArray(); expect(entities.length).toBe(0); }));