|
1 | 1 | import { QueryInput, QueryOutput } from 'aws-sdk/clients/dynamodb' |
2 | 2 | import * as moment from 'moment' |
3 | | -import { Observable } from 'rxjs' |
| 3 | +import { Observable, of } from 'rxjs' |
4 | 4 | import { getTableName } from '../../../../test/helper/get-table-name.function' |
5 | 5 | import { ComplexModel } from '../../../../test/models/complex.model' |
| 6 | +import { |
| 7 | + CustomId, |
| 8 | + ModelWithCustomMapperForSortKeyModel, |
| 9 | +} from '../../../../test/models/model-with-custom-mapper-for-sort-key.model' |
6 | 10 | import { INDEX_ACTIVE_CREATED_AT, ModelWithABunchOfIndexes } from '../../../../test/models/model-with-indexes.model' |
7 | 11 | import { DynamoRx } from '../../dynamo-rx' |
8 | 12 | import { attribute } from '../../expression/logical-operator/attribute.function' |
9 | 13 | import { QueryRequest } from './query.request' |
10 | 14 |
|
11 | 15 | export const DYNAMO_RX_MOCK: DynamoRx = <DynamoRx>{ |
12 | 16 | query(params: QueryInput): Observable<QueryOutput> { |
13 | | - return Observable.of({}) |
| 17 | + return of({}) |
14 | 18 | }, |
15 | 19 | } |
16 | 20 |
|
@@ -88,6 +92,24 @@ describe('query request', () => { |
88 | 92 | }) |
89 | 93 | }) |
90 | 94 |
|
| 95 | + describe('uses custom mapper for sortKey', () => { |
| 96 | + const request = new QueryRequest( |
| 97 | + <any>null, |
| 98 | + ModelWithCustomMapperForSortKeyModel, |
| 99 | + getTableName(ModelWithCustomMapperForSortKeyModel) |
| 100 | + ) |
| 101 | + |
| 102 | + request.whereSortKey().between(new CustomId(moment('2018-01-01'), 0), new CustomId(moment('2018-12-31'), 99999)) |
| 103 | + |
| 104 | + it('correct mapping', () => { |
| 105 | + expect(request.params.ExpressionAttributeValues).toBeDefined() |
| 106 | + expect(request.params.ExpressionAttributeValues).toEqual({ |
| 107 | + ':customId': { N: '2018010100000' }, |
| 108 | + ':customId_2': { N: '2018123199999' }, |
| 109 | + }) |
| 110 | + }) |
| 111 | + }) |
| 112 | + |
91 | 113 | describe('calls endpoint with correct params', () => { |
92 | 114 | const dynamoRx: DynamoRx = DYNAMO_RX_MOCK as DynamoRx |
93 | 115 | let querySpy |
|
0 commit comments