Skip to content

Commit ed62824

Browse files
authored
Adds v2 test lab triggers (#1241)
* init * adding in tests & fixing remote config tsdoc strings * adding exports * remove @Alpha from remote config since docs are published * add wrapTraceContext
1 parent cea9ebe commit ed62824

File tree

6 files changed

+343
-26
lines changed

6 files changed

+343
-26
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
"./v2/identity": "./lib/v2/providers/identity.js",
5858
"./v2/database": "./lib/v2/providers/database.js",
5959
"./v2/scheduler": "./lib/v2/providers/scheduler.js",
60-
"./v2/remoteConfig": "./lib/v2/providers/remoteConfig.js"
60+
"./v2/remoteConfig": "./lib/v2/providers/remoteConfig.js",
61+
"./v2/testLab": "./lib/v2/providers/testLab.js"
6162
},
6263
"typesVersions": {
6364
"*": {
@@ -150,6 +151,9 @@
150151
],
151152
"v2/remoteConfig": [
152153
"lib/v2/providers/remoteConfig"
154+
],
155+
"v2/testLab": [
156+
"lib/v2/providers/testLab"
153157
]
154158
}
155159
},

spec/v2/providers/testLab.spec.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2022 Firebase
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
import { expect } from "chai";
24+
import * as testLab from "../../../src/v2/providers/testLab";
25+
import * as options from "../../../src/v2/options";
26+
27+
describe("onTestMatrixCompleted", () => {
28+
afterEach(() => {
29+
options.setGlobalOptions({});
30+
});
31+
32+
it("should create a function with a handler", () => {
33+
const fn = testLab.onTestMatrixCompleted(() => 2);
34+
35+
expect(fn.__endpoint).to.deep.eq({
36+
platform: "gcfv2",
37+
labels: {},
38+
eventTrigger: {
39+
eventType: testLab.eventType,
40+
eventFilters: {},
41+
retry: false,
42+
},
43+
});
44+
expect(fn.run(1 as any)).to.eq(2);
45+
});
46+
47+
it("should create a function with opts and a handler", () => {
48+
options.setGlobalOptions({
49+
memory: "512MiB",
50+
region: "us-west1",
51+
});
52+
53+
const fn = testLab.onTestMatrixCompleted(
54+
{
55+
region: "us-central1",
56+
retry: true,
57+
},
58+
() => 2
59+
);
60+
61+
expect(fn.__endpoint).to.deep.eq({
62+
platform: "gcfv2",
63+
availableMemoryMb: 512,
64+
region: ["us-central1"],
65+
labels: {},
66+
eventTrigger: {
67+
eventType: testLab.eventType,
68+
eventFilters: {},
69+
retry: true,
70+
},
71+
});
72+
expect(fn.run(1 as any)).to.eq(2);
73+
});
74+
});

src/v2/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import * as scheduler from "./providers/scheduler";
3939
import * as storage from "./providers/storage";
4040
import * as tasks from "./providers/tasks";
4141
import * as remoteConfig from "./providers/remoteConfig";
42+
import * as testLab from "./providers/testLab";
4243

4344
export {
4445
alerts,
@@ -52,6 +53,7 @@ export {
5253
eventarc,
5354
scheduler,
5455
remoteConfig,
56+
testLab,
5557
};
5658

5759
export {

src/v2/providers/remoteConfig.ts

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,61 +27,61 @@ import { EventHandlerOptions, getGlobalOptions, optionsToEndpoint } from "../opt
2727
/** @internal */
2828
export const eventType = "google.firebase.remoteconfig.remoteConfig.v1.updated";
2929

30-
/* All the fields associated with the person/service account that wrote a Remote Config template. */
30+
/** All the fields associated with the person/service account that wrote a Remote Config template. */
3131
export interface ConfigUser {
32-
/* Display name. */
32+
/** Display name. */
3333
name: string;
3434

35-
/* Email address. */
35+
/** Email address. */
3636
email: string;
3737

38-
/* Image URL. */
38+
/** Image URL. */
3939
imageUrl: string;
4040
}
4141

42-
/* What type of update was associated with the Remote Config template version. */
42+
/** What type of update was associated with the Remote Config template version. */
4343
export type ConfigUpdateOrigin =
44-
/* Catch-all for unrecognized values. */
44+
/** Catch-all for unrecognized values. */
4545
| "REMOTE_CONFIG_UPDATE_ORIGIN_UNSPECIFIED"
46-
/* The update came from the Firebase UI. */
46+
/** The update came from the Firebase UI. */
4747
| "CONSOLE"
48-
/* The update came from the Remote Config REST API. */
48+
/** The update came from the Remote Config REST API. */
4949
| "REST_API"
50-
/* The update came from the Firebase Admin Node SDK. */
50+
/** The update came from the Firebase Admin Node SDK. */
5151
| "ADMIN_SDK_NODE";
5252

53-
/* Where the Remote Config update action originated. */
53+
/** Where the Remote Config update action originated. */
5454
export type ConfigUpdateType =
55-
/* Catch-all for unrecognized enum values */
55+
/** Catch-all for unrecognized enum values */
5656
| "REMOTE_CONFIG_UPDATE_TYPE_UNSPECIFIED"
57-
/* A regular incremental update */
57+
/** A regular incremental update */
5858
| "INCREMENTAL_UPDATE"
59-
/* A forced update. The ETag was specified as "*" in an UpdateRemoteConfigRequest request or the "Force Update" button was pressed on the console */
59+
/** A forced update. The ETag was specified as "*" in an UpdateRemoteConfigRequest request or the "Force Update" button was pressed on the console */
6060
| "FORCED_UPDATE"
61-
/* A rollback to a previous Remote Config template */
61+
/** A rollback to a previous Remote Config template */
6262
| "ROLLBACK";
6363

64-
/* The data within Firebase Remote Config update events. */
64+
/** The data within Firebase Remote Config update events. */
6565
export interface ConfigUpdateData {
66-
/* The version number of the version's corresponding Remote Config template. */
66+
/** The version number of the version's corresponding Remote Config template. */
6767
versionNumber: number;
6868

69-
/* When the Remote Config template was written to the Remote Config server. */
69+
/** When the Remote Config template was written to the Remote Config server. */
7070
updateTime: string;
7171

72-
/* Aggregation of all metadata fields about the account that performed the update. */
72+
/** Aggregation of all metadata fields about the account that performed the update. */
7373
updateUser: ConfigUser;
7474

75-
/* The user-provided description of the corresponding Remote Config template. */
75+
/** The user-provided description of the corresponding Remote Config template. */
7676
description: string;
7777

78-
/* Where the update action originated. */
78+
/** Where the update action originated. */
7979
updateOrigin: ConfigUpdateOrigin;
8080

81-
/* What type of update was made. */
81+
/** What type of update was made. */
8282
updateType: ConfigUpdateType;
8383

84-
/* Only present if this version is the result of a rollback, and will be the version number of the Remote Config template that was rolled-back to. */
84+
/** Only present if this version is the result of a rollback, and will be the version number of the Remote Config template that was rolled-back to. */
8585
rollbackSource: number;
8686
}
8787

@@ -90,7 +90,6 @@ export interface ConfigUpdateData {
9090
*
9191
* @param handler - Event handler which is run every time a Remote Config update occurs.
9292
* @returns A Cloud Function that you can export and deploy.
93-
* @alpha
9493
*/
9594
export function onConfigUpdated(
9695
handler: (event: CloudEvent<ConfigUpdateData>) => any | Promise<any>
@@ -102,7 +101,6 @@ export function onConfigUpdated(
102101
* @param opts - Options that can be set on an individual event-handling function.
103102
* @param handler - Event handler which is run every time a Remote Config update occurs.
104103
* @returns A Cloud Function that you can export and deploy.
105-
* @alpha
106104
*/
107105
export function onConfigUpdated(
108106
opts: EventHandlerOptions,
@@ -115,7 +113,6 @@ export function onConfigUpdated(
115113
* @param optsOrHandler - Options or an event handler.
116114
* @param handler - Event handler which is run every time a Remote Config update occurs.
117115
* @returns A Cloud Function that you can export and deploy.
118-
* @alpha
119116
*/
120117
export function onConfigUpdated(
121118
optsOrHandler:

0 commit comments

Comments
 (0)