fix: Symbol property could not be iterated in for-in (#39)
This commit is contained in:
parent
5662509f4c
commit
787d2b611f
@ -1,4 +1,4 @@
|
|||||||
import { literal } from 'sequelize';
|
import { literal, Op } from 'sequelize';
|
||||||
import { getDatabase } from '..';
|
import { getDatabase } from '..';
|
||||||
import Database from '../../database';
|
import Database from '../../database';
|
||||||
import Model, { ModelCtor } from '../../model';
|
import Model, { ModelCtor } from '../../model';
|
||||||
@ -55,6 +55,10 @@ beforeAll(() => {
|
|||||||
db.table({
|
db.table({
|
||||||
name: 'foos',
|
name: 'foos',
|
||||||
fields: [
|
fields: [
|
||||||
|
{
|
||||||
|
type: 'int',
|
||||||
|
name: 'f_g61p'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type: 'hasMany',
|
type: 'hasMany',
|
||||||
name: 'bars',
|
name: 'bars',
|
||||||
@ -99,6 +103,19 @@ describe('parseApiJson', () => {
|
|||||||
});
|
});
|
||||||
expect(data).toEqual({ where: { col1: 'co2' } });
|
expect(data).toEqual({ where: { col1: 'co2' } });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('filter with condition operator', () => {
|
||||||
|
const data = Foo.parseApiJson({
|
||||||
|
filter: {"and":[{"f_g61p.eq":23}]}
|
||||||
|
});
|
||||||
|
expect(data).toEqual({
|
||||||
|
where: {
|
||||||
|
[Op.and]: [
|
||||||
|
{ f_g61p: { [Op.eq]: 23 } }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('fields', () => {
|
it('fields', () => {
|
||||||
const data = Foo.parseApiJson({
|
const data = Foo.parseApiJson({
|
||||||
|
@ -1,10 +1,40 @@
|
|||||||
import { Op } from "sequelize";
|
import { Op } from "sequelize";
|
||||||
import Database from "../../database";
|
import Database from "../../database";
|
||||||
import Model, { ModelCtor } from '../../model';
|
|
||||||
import { toWhere } from "../../utils";
|
import { toWhere } from "../../utils";
|
||||||
import { getDatabase } from "..";
|
import { getDatabase } from "..";
|
||||||
|
|
||||||
describe('utils.toWhere', () => {
|
describe('utils.toWhere', () => {
|
||||||
|
let db: Database;
|
||||||
|
beforeAll(() => {
|
||||||
|
db = getDatabase();
|
||||||
|
db.table({
|
||||||
|
name: 'users',
|
||||||
|
});
|
||||||
|
db.table({
|
||||||
|
name: 'posts',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: 'title'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'belongsTo',
|
||||||
|
name: 'user',
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
db.table({
|
||||||
|
name: 'categories',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
type: 'hasMany',
|
||||||
|
name: 'posts',
|
||||||
|
}
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
afterAll(() => db.close());
|
||||||
|
|
||||||
describe('single', () => {
|
describe('single', () => {
|
||||||
it('=', () => {
|
it('=', () => {
|
||||||
const where = toWhere({
|
const where = toWhere({
|
||||||
@ -213,6 +243,18 @@ describe('utils.toWhere', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('logical and with condition operator in field', () => {
|
||||||
|
const Post = db.getModel('posts');
|
||||||
|
const data = toWhere({"and":[{"title.eq": '23'}]}, {
|
||||||
|
model: Post
|
||||||
|
});
|
||||||
|
expect(data).toEqual({
|
||||||
|
[Op.and]: [
|
||||||
|
{ title: { [Op.eq]: '23' } }
|
||||||
|
]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// TODO: bug
|
// TODO: bug
|
||||||
it.skip('field as "or"', () => {
|
it.skip('field as "or"', () => {
|
||||||
expect(toWhere({
|
expect(toWhere({
|
||||||
@ -233,33 +275,6 @@ describe('utils.toWhere', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('association', () => {
|
describe('association', () => {
|
||||||
let db: Database;
|
|
||||||
beforeAll(() => {
|
|
||||||
db = getDatabase();
|
|
||||||
db.table({
|
|
||||||
name: 'users',
|
|
||||||
});
|
|
||||||
db.table({
|
|
||||||
name: 'posts',
|
|
||||||
fields: [
|
|
||||||
{
|
|
||||||
type: 'belongsTo',
|
|
||||||
name: 'user',
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
db.table({
|
|
||||||
name: 'categories',
|
|
||||||
fields: [
|
|
||||||
{
|
|
||||||
type: 'hasMany',
|
|
||||||
name: 'posts',
|
|
||||||
}
|
|
||||||
],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
afterAll(() => db.close());
|
|
||||||
|
|
||||||
const toWhereExpect = (options: any) => {
|
const toWhereExpect = (options: any) => {
|
||||||
const Category = db.getModel('categories');
|
const Category = db.getModel('categories');
|
||||||
const where = toWhere(options, {
|
const where = toWhere(options, {
|
||||||
|
@ -273,7 +273,7 @@ export function toInclude(options: any, context: ToIncludeContext = {}) {
|
|||||||
data.distinct = true;
|
data.distinct = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Object.keys(where).length > 0) {
|
if (Reflect.ownKeys(where).length > 0) {
|
||||||
data.where = where;
|
data.where = where;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user