UNPKG

tspace-mysql

Version:

Tspace MySQL is a promise-based ORM for Node.js, designed with modern TypeScript and providing type safety for schema databases.

72 lines 3.12 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const chai_1 = __importStar(require("chai")); const mocha_1 = require("mocha"); const chai_json_schema_1 = __importDefault(require("chai-json-schema")); const lib_1 = require("../lib"); chai_1.default.use(chai_json_schema_1.default); (0, mocha_1.describe)('Testing View', function () { /* ##################################################### */ (0, mocha_1.it)(`View: Start to create view 'user_post_count' for testing fetching data`, async function () { class UserPostCount extends lib_1.View { boot() { this.createView({ synchronize: true, expression: ` SELECT ROW_NUMBER() OVER (ORDER BY users.id) AS id, users.id AS user_id, users.name, users.email, COUNT(posts.id) AS post_count FROM users LEFT JOIN posts ON users.id = posts.user_id GROUP BY users.id, users.name ` }); } } const userPostCountView = await new UserPostCount().get(); (0, chai_1.expect)(userPostCountView).to.be.an('array'); (0, chai_1.expect)(userPostCountView).to.be.jsonSchema({ type: 'array', items: { type: 'object', required: ['id', 'user_id', 'name', 'post_count'], properties: { id: { type: 'integer' }, user_id: { type: 'integer' }, name: { type: 'string' }, email: { type: 'string' }, post_count: { type: 'integer' } } } }); }); /* ###################################################### */ }); //# sourceMappingURL=05-View.test.js.map