opencart-manager
Version:
Node.js package helping to manage your opencart store data easily.
48 lines (47 loc) • 2.77 kB
JavaScript
;
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_option_1 = __importDefault(require("./product-option"));
const fakeDatabase = new database_1.default();
const model = new product_option_1.default(fakeDatabase);
let id;
const table = "product_option";
const data = { value: "text" };
const updated = Object.assign(Object.assign({}, data), { value: "text updated" });
const criteria = { productOptionId: -1 };
const initialValues = initial_1.initialProductOption;
test("insert", () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield model.insert(data);
expect(result).toBeResponseHeaders();
criteria.productOptionId = 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();
}));