|
| 1 | +/** |
| 2 | + * @license Apache-2.0 |
| 3 | + * @copyright Cube Dev, Inc. |
| 4 | + * @fileoverview SqlQuery class unit tests. |
| 5 | + */ |
| 6 | + |
| 7 | +/* globals describe,it,expect */ |
| 8 | + |
| 9 | +import SqlQuery, { SqlQueryTuple, SqlData, SqlQueryWrapper } from '../src/SqlQuery'; |
| 10 | + |
| 11 | +describe('SqlQuery', () => { |
| 12 | + const mockCacheKeyQueriesTuple: SqlQueryTuple = [ |
| 13 | + 'SELECT FLOOR((-25200 + EXTRACT(EPOCH FROM NOW())) / 600) as refresh_key', |
| 14 | + [], |
| 15 | + { |
| 16 | + external: false, |
| 17 | + renewalThreshold: 60 |
| 18 | + } |
| 19 | + ]; |
| 20 | + |
| 21 | + const mockSqlTuple: SqlQueryTuple = [ |
| 22 | + 'SELECT count(*) "base_orders__count" FROM base_orders WHERE base_orders.continent = ?', |
| 23 | + ['Europe'], |
| 24 | + ]; |
| 25 | + |
| 26 | + const mockSqlData: SqlData = { |
| 27 | + aliasNameToMember: { base_orders__count: 'base_orders.count' }, |
| 28 | + cacheKeyQueries: [mockCacheKeyQueriesTuple], |
| 29 | + dataSource: 'default', |
| 30 | + external: false, |
| 31 | + sql: mockSqlTuple, |
| 32 | + preAggregations: [], |
| 33 | + rollupMatchResults: [], |
| 34 | + }; |
| 35 | + |
| 36 | + const mockWrapper: SqlQueryWrapper = { |
| 37 | + sql: mockSqlData, |
| 38 | + }; |
| 39 | + |
| 40 | + it('should construct without error', () => { |
| 41 | + expect(() => new SqlQuery(mockWrapper)).not.toThrow(); |
| 42 | + }); |
| 43 | + |
| 44 | + it('rawQuery should return the original SqlData', () => { |
| 45 | + const query = new SqlQuery(mockWrapper); |
| 46 | + expect(query.rawQuery()).toEqual(mockSqlData); |
| 47 | + }); |
| 48 | + |
| 49 | + it('sql should return the first element (SQL string) from the sql tuple', () => { |
| 50 | + const query = new SqlQuery(mockWrapper); |
| 51 | + expect(query.sql()).toBe('SELECT count(*) "base_orders__count" FROM base_orders WHERE base_orders.continent = ?'); |
| 52 | + }); |
| 53 | +}); |
0 commit comments