File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ if (typeof (Symbol as any).asyncIterator === 'undefined') {
66import { Client } from './client'
77import { Page } from './page'
88import { PageParams } from './types'
9+ import { validate } from './validate'
910
1011/**
1112 * A query for Sequence items.
@@ -20,7 +21,11 @@ export class Query<QueryParamType> {
2021 private itemName : string ,
2122 private method : string ,
2223 private queryParams ?: QueryParamType
23- ) { }
24+ ) {
25+ if ( queryParams ) {
26+ validate ( queryParams , 'QueryParamsSchema' )
27+ }
28+ }
2429
2530 /**
2631 * Retrieve a page of results.
Original file line number Diff line number Diff line change @@ -46,3 +46,24 @@ ajv.addSchema(
4646 } ,
4747 'UpdateTagsSchema'
4848)
49+
50+ ajv . addSchema (
51+ {
52+ type : 'object' ,
53+ properties : {
54+ filter : { type : 'string' } ,
55+ filterParams : {
56+ type : 'array' ,
57+ items : {
58+ anyOf : [ { type : 'string' } , { type : 'number' } ] ,
59+ } ,
60+ } ,
61+ pageSize : { type : 'number' } ,
62+ cursor : { type : 'string' } ,
63+ summary : { type : 'boolean' } ,
64+ groupBy : { type : 'array' , items : { type : 'string' } } ,
65+ } ,
66+ additionalProperties : false ,
67+ } ,
68+ 'QueryParamsSchema'
69+ )
Original file line number Diff line number Diff line change @@ -73,4 +73,36 @@ describe('Schemas', () => {
7373 } )
7474 } )
7575 } )
76+
77+ describe ( 'Query' , ( ) => {
78+ it ( 'rejects list with after' , ( ) => {
79+ try {
80+ client . accounts . list ( { after : 'foo' } ) . all ( )
81+ } catch ( err ) {
82+ expect ( err . message ) . to . contain ( "should NOT have additional properties '.after'" )
83+ return
84+ }
85+ assert ( false , 'should not accept `after` field' )
86+ } )
87+
88+ it ( 'rejects sum with sum by' , ( ) => {
89+ try {
90+ client . actions . sum ( { sumBy : [ 'foo' ] } ) . all ( )
91+ } catch ( err ) {
92+ expect ( err . message ) . to . contain ( "should NOT have additional properties '.sumBy'" )
93+ return
94+ }
95+ assert ( false , 'should not accept `sumBy` field' )
96+ } )
97+
98+ it ( 'rejects list with start time' , ( ) => {
99+ try {
100+ client . transactions . list ( { startTime : 0 } ) . all ( )
101+ } catch ( err ) {
102+ expect ( err . message ) . to . contain ( "should NOT have additional properties '.startTime'" )
103+ return
104+ }
105+ assert ( false , 'should not accept `startTime` field' )
106+ } )
107+ } )
76108} )
You can’t perform that action at this time.
0 commit comments