@@ -3,9 +3,6 @@ import { afterAll, beforeAll, expect, test } from "vitest";
33import {
44 StudyStatus ,
55 ParticipantGroupStatus ,
6- getSerializer ,
7- StudyProtocolSnapshot ,
8- DefaultSerializer ,
96 DataStreamsConfiguration ,
107 NamespacedId ,
118 MutableDataStreamSequence ,
@@ -15,6 +12,10 @@ import {
1512 Measurement ,
1613 Geolocation ,
1714 toList ,
15+ CompletedAppTask ,
16+ DefaultSerializer ,
17+ getSerializer ,
18+ StudyProtocolSnapshot ,
1819} from "@/shared" ;
1920import { CarpTestClient } from "@/client" ;
2021import { STUDY_PROTOCOL } from "../consts" ;
@@ -90,13 +91,7 @@ describe("DataStreams", () => {
9091
9192 await testClient . authentication . refresh ( ) ;
9293
93- namespaceId = new NamespacedId (
94- STUDY_PROTOCOL . tasks [ 0 ] . measures [ 0 ] . type . replace (
95- `.${ STUDY_PROTOCOL . tasks [ 0 ] . measures [ 0 ] . type . split ( "." ) . pop ( ) } ` ,
96- "" ,
97- ) ,
98- STUDY_PROTOCOL . tasks [ 0 ] . measures [ 0 ] . type . split ( "." ) . pop ( ) ,
99- ) ;
94+ namespaceId = new NamespacedId ( "dk.cachet.carp" , "completedapptask" ) ;
10095 await expect (
10196 testClient . dataStreams . openDataStreams ( {
10297 studyDeploymentId : participantGroupStatus . id . stringRepresentation ,
@@ -132,7 +127,12 @@ describe("DataStreams", () => {
132127 toLong ( 1 ) ,
133128 null ,
134129 namespaceId ,
135- new Geolocation ( 57 , 45 , null ) as any ,
130+ new CompletedAppTask (
131+ "Monitor movement" ,
132+ "sensing" ,
133+ "dk.cachet.carp.geolocation" ,
134+ new Geolocation ( 57 , 45 , null ) as any ,
135+ ) as any ,
136136 ) ,
137137 ] ) ,
138138 ) ;
@@ -201,7 +201,12 @@ describe("DataStreams", () => {
201201 toLong ( 1 ) ,
202202 null ,
203203 namespaceId ,
204- new Geolocation ( 57 , 45 , null ) as any ,
204+ new CompletedAppTask (
205+ "Monitor movement" ,
206+ "sensing" ,
207+ "dk.cachet.carp.geolocation" ,
208+ new Geolocation ( 57 , 45 , null ) as any ,
209+ ) as any ,
205210 ) ,
206211 ] ) ,
207212 ) ;
@@ -293,6 +298,60 @@ describe("DataStreams", () => {
293298 } ) ;
294299 } ) ;
295300
301+ test ( "should be able to get summary for datastreams" , async ( ) => {
302+ const batch = new CarpDataStreamBatch ( ) ;
303+ const sequence = new MutableDataStreamSequence (
304+ new DataStreamId (
305+ participantGroupStatus . id ,
306+ STUDY_PROTOCOL . primaryDevices [ 0 ] . roleName ,
307+ namespaceId ,
308+ ) ,
309+ toLong ( 1 ) ,
310+ toList ( [ 1 ] ) ,
311+ SyncPoint . Companion . UnixEpoch ,
312+ ) ;
313+ sequence . appendMeasurementsList (
314+ toList ( [
315+ new Measurement (
316+ toLong ( 1 ) ,
317+ null ,
318+ namespaceId ,
319+ new CompletedAppTask (
320+ "Monitor movement" ,
321+ "sensing" ,
322+ "dk.cachet.carp.geolocation" ,
323+ new Geolocation ( 57 , 45 , null ) as any ,
324+ ) as any ,
325+ ) ,
326+ ] ) ,
327+ ) ;
328+
329+ batch . sequences = [ sequence ] ;
330+
331+ await expect (
332+ testClient . dataStreams . appendToDataStreams ( {
333+ studyDeploymentId : participantGroupStatus . id . stringRepresentation ,
334+ batch,
335+ } ) ,
336+ ) . resolves . not . toThrow ( ) ;
337+
338+ const response = await testClient . dataStreams . getDataStreamSummary ( {
339+ study_id : study . studyId . stringRepresentation ,
340+ scope : "study" ,
341+ type : "sensing" ,
342+ from : new Date ( Date . now ( ) - 1000 * 60 * 60 * 24 * 28 ) . toISOString ( ) ,
343+ to : new Date ( ) . toISOString ( ) ,
344+ } ) ;
345+
346+ expect ( response . studyId ) . toBe ( study . studyId . stringRepresentation ) ;
347+ expect ( response . scope ) . toBe ( "study" ) ;
348+ expect ( response . type ) . toBe ( "sensing" ) ;
349+ response . data . forEach ( ( data ) => {
350+ expect ( data . quantity ) . to . be . at . least ( 1 ) ;
351+ expect ( data . task ) . toBe ( "Monitor movement" ) ;
352+ } ) ;
353+ } ) ;
354+
296355 afterAll ( async ( ) => {
297356 if ( study ) {
298357 if ( participantGroupStatus ) {
0 commit comments