@@ -19,16 +19,20 @@ import { Message } from '../../../../src/core/message.js';
1919import { MessageStoreLevel } from '../../../../src/store/message-store-level.js' ;
2020import { RecordsQueryHandler } from '../../../../src/interfaces/records/handlers/records-query.js' ;
2121import { StorageController } from '../../../../src/store/storage-controller.js' ;
22- import { Temporal } from '@js-temporal/polyfill' ;
2322import { TestDataGenerator } from '../../../utils/test-data-generator.js' ;
2423import { TestStubGenerator } from '../../../utils/test-stub-generator.js' ;
24+ import { toTemporalInstant } from '@js-temporal/polyfill' ;
2525
2626import { constructRecordsWriteIndexes } from '../../../../src/interfaces/records/handlers/records-write.js' ;
2727import { DataStream , DidResolver , Dwn , HdKey , KeyDerivationScheme , Records } from '../../../../src/index.js' ;
2828import { DateSort , RecordsQuery } from '../../../../src/interfaces/records/messages/records-query.js' ;
2929
3030chai . use ( chaiAsPromised ) ;
3131
32+ function createDateString ( d : Date ) : string {
33+ return toTemporalInstant . call ( d ) . toString ( { smallestUnit : 'microseconds' } ) ;
34+ }
35+
3236describe ( 'RecordsQueryHandler.handle()' , ( ) => {
3337 describe ( 'functional tests' , ( ) => {
3438 let didResolver : DidResolver ;
@@ -183,11 +187,12 @@ describe('RecordsQueryHandler.handle()', () => {
183187 expect ( reply3 . entries ?. length ) . to . equal ( 0 ) ;
184188 } ) ;
185189
190+
186191 it ( 'should be able to range query by `dateCreated`' , async ( ) => {
187192 // scenario: 3 records authored by alice, created on first of 2021, 2022, and 2023 respectively, only the first 2 records share the same schema
188- const firstDayOf2021 = Temporal . PlainDateTime . from ( { year : 2021 , month : 1 , day : 1 } ) . toString ( { smallestUnit : 'microseconds' } ) ;
189- const firstDayOf2022 = Temporal . PlainDateTime . from ( { year : 2022 , month : 1 , day : 1 } ) . toString ( { smallestUnit : 'microseconds' } ) ;
190- const firstDayOf2023 = Temporal . PlainDateTime . from ( { year : 2023 , month : 1 , day : 1 } ) . toString ( { smallestUnit : 'microseconds' } ) ;
193+ const firstDayOf2021 = createDateString ( new Date ( 2021 , 1 , 1 ) ) ;
194+ const firstDayOf2022 = createDateString ( new Date ( 2022 , 1 , 1 ) ) ;
195+ const firstDayOf2023 = createDateString ( new Date ( 2023 , 1 , 1 ) ) ;
191196 const alice = await DidKeyResolver . generate ( ) ;
192197 const write1 = await TestDataGenerator . generateRecordsWrite ( { requester : alice , dateCreated : firstDayOf2021 , dateModified : firstDayOf2021 } ) ;
193198 const write2 = await TestDataGenerator . generateRecordsWrite ( { requester : alice , dateCreated : firstDayOf2022 , dateModified : firstDayOf2022 } ) ;
@@ -202,7 +207,7 @@ describe('RecordsQueryHandler.handle()', () => {
202207 expect ( writeReply3 . status . code ) . to . equal ( 202 ) ;
203208
204209 // testing `from` range
205- const lastDayOf2021 = Temporal . PlainDateTime . from ( { year : 2021 , month : 12 , day : 31 } ) . toString ( { smallestUnit : 'microseconds' } ) ;
210+ const lastDayOf2021 = createDateString ( new Date ( 2021 , 12 , 31 ) ) ;
206211 const recordsQuery1 = await TestDataGenerator . generateRecordsQuery ( {
207212 requester : alice ,
208213 filter : { dateCreated : { from : lastDayOf2021 } } ,
@@ -214,7 +219,7 @@ describe('RecordsQueryHandler.handle()', () => {
214219 expect ( reply1 . entries ! [ 1 ] . encodedData ) . to . equal ( Encoder . bytesToBase64Url ( write3 . dataBytes ! ) ) ;
215220
216221 // testing `to` range
217- const lastDayOf2022 = Temporal . PlainDateTime . from ( { year : 2022 , month : 12 , day : 31 } ) . toString ( { smallestUnit : 'microseconds' } ) ;
222+ const lastDayOf2022 = createDateString ( new Date ( 2022 , 12 , 31 ) ) ;
218223 const recordsQuery2 = await TestDataGenerator . generateRecordsQuery ( {
219224 requester : alice ,
220225 filter : { dateCreated : { to : lastDayOf2022 } } ,
@@ -226,7 +231,7 @@ describe('RecordsQueryHandler.handle()', () => {
226231 expect ( reply2 . entries ! [ 1 ] . encodedData ) . to . equal ( Encoder . bytesToBase64Url ( write2 . dataBytes ! ) ) ;
227232
228233 // testing `from` and `to` range
229- const lastDayOf2023 = Temporal . PlainDateTime . from ( { year : 2023 , month : 12 , day : 31 } ) . toString ( { smallestUnit : 'microseconds' } ) ;
234+ const lastDayOf2023 = createDateString ( new Date ( 2023 , 12 , 31 ) ) ;
230235 const recordsQuery3 = await TestDataGenerator . generateRecordsQuery ( {
231236 requester : alice ,
232237 filter : { dateCreated : { from : lastDayOf2022 , to : lastDayOf2023 } } ,
@@ -249,9 +254,9 @@ describe('RecordsQueryHandler.handle()', () => {
249254
250255 it ( 'should be able use range and exact match queries at the same time' , async ( ) => {
251256 // scenario: 3 records authored by alice, created on first of 2021, 2022, and 2023 respectively, only the first 2 records share the same schema
252- const firstDayOf2021 = Temporal . PlainDateTime . from ( { year : 2021 , month : 1 , day : 1 } ) . toString ( { smallestUnit : 'microseconds' } ) ;
253- const firstDayOf2022 = Temporal . PlainDateTime . from ( { year : 2022 , month : 1 , day : 1 } ) . toString ( { smallestUnit : 'microseconds' } ) ;
254- const firstDayOf2023 = Temporal . PlainDateTime . from ( { year : 2023 , month : 1 , day : 1 } ) . toString ( { smallestUnit : 'microseconds' } ) ;
257+ const firstDayOf2021 = createDateString ( new Date ( 2021 , 1 , 1 ) ) ;
258+ const firstDayOf2022 = createDateString ( new Date ( 2022 , 1 , 1 ) ) ;
259+ const firstDayOf2023 = createDateString ( new Date ( 2023 , 1 , 1 ) ) ;
255260 const alice = await DidKeyResolver . generate ( ) ;
256261 const schema = '2021And2022Schema' ;
257262 const write1 = await TestDataGenerator . generateRecordsWrite ( {
@@ -273,8 +278,8 @@ describe('RecordsQueryHandler.handle()', () => {
273278 expect ( writeReply3 . status . code ) . to . equal ( 202 ) ;
274279
275280 // testing range criterion with another exact match
276- const lastDayOf2021 = Temporal . PlainDateTime . from ( { year : 2021 , month : 12 , day : 31 } ) . toString ( { smallestUnit : 'microseconds' } ) ;
277- const lastDayOf2023 = Temporal . PlainDateTime . from ( { year : 2023 , month : 12 , day : 31 } ) . toString ( { smallestUnit : 'microseconds' } ) ;
281+ const lastDayOf2021 = createDateString ( new Date ( 2021 , 12 , 31 ) ) ;
282+ const lastDayOf2023 = createDateString ( new Date ( 2023 , 12 , 31 ) ) ;
278283 const recordsQuery5 = await TestDataGenerator . generateRecordsQuery ( {
279284 requester : alice ,
280285 filter : {
0 commit comments