UNPKG

opencart-manager

Version:

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

65 lines (64 loc) 3.38 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 initial_1 = require("../../initial"); const utils_1 = require("../../utils"); const product_1 = __importDefault(require("./product")); const fakeDatabase = new database_1.default(); const model = new product_1.default(fakeDatabase); let id; const table = "product"; const data = { price: 123 }; const updated = Object.assign(Object.assign({}, data), { price: 234 }); const criteria = { productId: -1 }; const initialValues = initial_1.initialProduct; test("insert", () => __awaiter(void 0, void 0, void 0, function* () { const result = yield model.insert(data); expect(result).toBeResponseHeaders(); criteria.productId = id = result.insertId; expect(fakeDatabase.mocks.insert).toHaveBeenNthCalledWith(1, table, utils_1.toFieldset(Object.assign(Object.assign({}, initialValues), data))); })); test("select", () => __awaiter(void 0, void 0, void 0, function* () { const rows = yield model.select(criteria); expect(fakeDatabase.mocks.select).toHaveBeenNthCalledWith(1, table, criteria); expect(rows[0]).toStrictEqual(expect.objectContaining(utils_1.toFieldset(Object.assign(Object.assign({}, initialValues), data)))); })); test("update", () => __awaiter(void 0, void 0, void 0, function* () { const result = yield model.update(criteria, updated); expect(fakeDatabase.mocks.update).toHaveBeenNthCalledWith(1, table, criteria, utils_1.toFieldset(updated)); expect(result).toBeResponseHeaders(); })); test("delete", () => __awaiter(void 0, void 0, void 0, function* () { const result = yield model.delete(criteria); expect(fakeDatabase.mocks.delete).toHaveBeenNthCalledWith(1, table, criteria); expect(result).toBeResponseHeaders(); })); test("toCategory", () => __awaiter(void 0, void 0, void 0, function* () { const result = yield model.toCategory(id, 123, 0); expect(fakeDatabase.mocks.insert).toHaveBeenNthCalledWith(2, table + "_to_category", { productId: id, categoryId: 123, mainCategory: 0, }); expect(result).toBeResponseHeaders(); })); test("toStore", () => __awaiter(void 0, void 0, void 0, function* () { const result = yield model.toStore(id, 1); expect(fakeDatabase.mocks.insert).toHaveBeenNthCalledWith(3, table + "_to_store", { productId: id, storeId: 1, }); expect(result).toBeResponseHeaders(); }));