Skip to content

Commit cac21b2

Browse files
Added tests for scheduled v2
1 parent 6e4c2f4 commit cac21b2

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

spec/v2.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import { expect } from 'chai';
2424

2525
import { wrapV2 } from '../src/v2';
26+
import type { WrappedV2ScheduledFunction } from '../src/v2';
2627

2728
import {
2829
CloudFunction,
@@ -35,6 +36,7 @@ import {
3536
eventarc,
3637
https,
3738
firestore,
39+
scheduler,
3840
} from 'firebase-functions/v2';
3941
import { defineString } from 'firebase-functions/params';
4042
import { makeDataSnapshot } from '../src/providers/database';
@@ -1422,6 +1424,41 @@ describe('v2', () => {
14221424
});
14231425
});
14241426

1427+
describe('scheduler', () => {
1428+
describe('onSchedule()', () => {
1429+
it('should return correct data', async () => {
1430+
const scheduledFunction = scheduler.onSchedule(
1431+
'every 5 minutes',
1432+
(_e) => {}
1433+
);
1434+
1435+
scheduledFunction.__endpoint = {
1436+
platform: 'gcfv2',
1437+
labels: {},
1438+
scheduleTrigger: {
1439+
schedule: 'every 5 minutes',
1440+
},
1441+
concurrency: 20,
1442+
minInstances: 3,
1443+
region: ['us-west1', 'us-central1'],
1444+
};
1445+
1446+
let wrappedFunction: WrappedV2ScheduledFunction;
1447+
1448+
expect(
1449+
() => (wrappedFunction = wrapV2(scheduledFunction))
1450+
).not.to.throw();
1451+
1452+
const result = await wrappedFunction({
1453+
scheduleTime: '2024-01-01T00:00:00Z',
1454+
jobName: 'test-job',
1455+
});
1456+
1457+
expect(result).to.be.undefined;
1458+
});
1459+
});
1460+
});
1461+
14251462
describe('callable functions', () => {
14261463
it('should return correct data', async () => {
14271464
const cloudFunction = https.onCall(() => 'hello');

0 commit comments

Comments
 (0)