-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
validate the usage of constant values (#99)
* validate the usage of constant values * 2.5.23
- Loading branch information
1 parent
c2914b9
commit b4f123e
Showing
5 changed files
with
116 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// eslint-disable-next-line no-unused-vars | ||
import {QueryEntity, QueryExpression, QueryField} from '../index'; | ||
import { QueryValueRef } from '../query'; | ||
import {MemoryAdapter} from './test/TestMemoryAdapter'; | ||
import Ajv from 'ajv'; | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
describe('SqlFormatter', () => { | ||
|
||
/** | ||
* @type {MemoryAdapter} | ||
*/ | ||
let db; | ||
beforeAll(() => { | ||
db = new MemoryAdapter({ | ||
name: 'local', | ||
database: './spec/db/local.db' | ||
}); | ||
}); | ||
afterAll(async () => { | ||
if (db) { | ||
await db.closeAsync(); | ||
} | ||
}) | ||
it('should format field expression', async () => { | ||
const Products = new QueryEntity('ProductData'); | ||
const q = new QueryExpression().select( | ||
new QueryField('id').from(Products), | ||
new QueryField('name').from(Products) | ||
).from(Products).take(25); | ||
const items = await db.executeAsync(q); | ||
expect(items.length).toBeTruthy(); | ||
|
||
const schema = { | ||
type: 'object', | ||
properties: { | ||
id: {type: 'number'}, | ||
name: {type: 'string'} | ||
}, | ||
required: ['id', 'name'], | ||
additionalProperties: false | ||
}; | ||
|
||
const validate = new Ajv().compile(schema); | ||
items.forEach((item) => expect(validate(item)).toBeTruthy()); | ||
}); | ||
|
||
it('should format field with method', async () => { | ||
const Products = new QueryEntity('ProductData'); | ||
const q = new QueryExpression().select( | ||
new QueryField('id').from(Products), | ||
new QueryField({ | ||
description: { | ||
$concat: [ | ||
new QueryField('model').from(Products), | ||
' ', | ||
new QueryField('name').from(Products), | ||
] | ||
} | ||
}) | ||
).from(Products).take(25); | ||
const items = await db.executeAsync(q); | ||
expect(items.length).toBeTruthy(); | ||
items.forEach((item) => expect(item.description).toBeTruthy()); | ||
}); | ||
|
||
it('should format field with constant', async () => { | ||
const Products = new QueryEntity('ProductData'); | ||
const q = new QueryExpression().select( | ||
new QueryField('id').from(Products), | ||
new QueryField({ | ||
status: { | ||
$value: 'active' | ||
} | ||
}) | ||
).from(Products).take(25); | ||
const items = await db.executeAsync(q); | ||
expect(items.length).toBeTruthy(); | ||
items.forEach((item) => expect(item.status).toBeTruthy()); | ||
}); | ||
|
||
|
||
}); |