@@ -18,40 +18,53 @@ describe("Firebase Tasks (v1)", () => {
18
18
19
19
describe ( "task queue onDispatch trigger" , ( ) => {
20
20
let loggedContext : admin . firestore . DocumentData | undefined ;
21
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
21
22
let taskId : string ;
22
23
23
24
beforeAll ( async ( ) => {
24
25
// Function name becomes the queue name in v1, no separators needed
25
26
const queueName = `tasksOnDispatchTests${ testId } ` ;
27
+ const projectId = process . env . GCLOUD_PROJECT || "functions-integration-tests" ;
28
+ const region = "us-central1" ;
29
+ const url = `https://${ region } -${ projectId } .cloudfunctions.net/${ queueName } ` ;
26
30
27
- taskId = await createTask ( queueName , testId ) ;
31
+ // Use Google Cloud Tasks SDK to get proper Cloud Tasks event context
32
+ taskId = await createTask ( projectId , queueName , region , url , { data : { testId } } ) ;
28
33
29
- loggedContext = await retry ( ( ) =>
30
- admin
31
- . firestore ( )
32
- . collection ( "tasksOnDispatchTests" )
33
- . doc ( testId )
34
- . get ( )
35
- . then ( ( logSnapshot ) => logSnapshot . data ( ) )
34
+ loggedContext = await retry (
35
+ ( ) => {
36
+ console . log ( `🔍 Checking Firestore for document: tasksOnDispatchTests/${ testId } ` ) ;
37
+ return admin
38
+ . firestore ( )
39
+ . collection ( "tasksOnDispatchTests" )
40
+ . doc ( testId )
41
+ . get ( )
42
+ . then ( ( logSnapshot ) => {
43
+ const data = logSnapshot . data ( ) ;
44
+ console . log ( `📄 Firestore data:` , data ) ;
45
+ return data ;
46
+ } ) ;
47
+ } ,
48
+ { maxRetries : 30 , checkForUndefined : true }
36
49
) ;
37
50
} ) ;
38
51
39
- it ( "should have the right eventType " , ( ) => {
40
- expect ( loggedContext ?. eventType ) . toEqual ( "google.cloud.tasks.queue.v2.task.dispatch" ) ;
52
+ it ( "should have correct event id " , ( ) => {
53
+ expect ( loggedContext ?. id ) . toBeDefined ( ) ;
41
54
} ) ;
42
55
43
- it ( "should have eventId " , ( ) => {
44
- expect ( loggedContext ?. eventId ) . toBeDefined ( ) ;
56
+ it ( "should have queue name " , ( ) => {
57
+ expect ( loggedContext ?. queueName ) . toEqual ( `tasksOnDispatchTests ${ testId } ` ) ;
45
58
} ) ;
46
59
47
- it ( "should have timestamp" , ( ) => {
48
- expect ( loggedContext ?. timestamp ) . toBeDefined ( ) ;
60
+ it ( "should have retry count" , ( ) => {
61
+ expect ( loggedContext ?. retryCount ) . toBeDefined ( ) ;
62
+ expect ( typeof loggedContext ?. retryCount ) . toBe ( "number" ) ;
49
63
} ) ;
50
64
51
- it ( "should have resource" , ( ) => {
52
- expect ( loggedContext ?. resource ) . toBeDefined ( ) ;
53
- expect ( loggedContext ?. resource ?. service ) . toEqual ( "cloudtasks.googleapis.com" ) ;
54
- expect ( loggedContext ?. resource ?. name ) . toContain ( taskId ) ;
65
+ it ( "should have execution count" , ( ) => {
66
+ expect ( loggedContext ?. executionCount ) . toBeDefined ( ) ;
67
+ expect ( typeof loggedContext ?. executionCount ) . toBe ( "number" ) ;
55
68
} ) ;
56
69
} ) ;
57
- } ) ;
70
+ } ) ;
0 commit comments