Skip to content

Adds v2 test lab triggers #1241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"./v2/identity": "./lib/v2/providers/identity.js",
"./v2/database": "./lib/v2/providers/database.js",
"./v2/scheduler": "./lib/v2/providers/scheduler.js",
"./v2/remoteConfig": "./lib/v2/providers/remoteConfig.js"
"./v2/remoteConfig": "./lib/v2/providers/remoteConfig.js",
"./v2/testLab": "./lib/v2/providers/testLab.js"
},
"typesVersions": {
"*": {
Expand Down Expand Up @@ -150,6 +151,9 @@
],
"v2/remoteConfig": [
"lib/v2/providers/remoteConfig"
],
"v2/testLab": [
"lib/v2/providers/testLab"
]
}
},
Expand Down
74 changes: 74 additions & 0 deletions spec/v2/providers/testLab.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// The MIT License (MIT)
//
// Copyright (c) 2022 Firebase
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import { expect } from "chai";
import * as testLab from "../../../src/v2/providers/testLab";
import * as options from "../../../src/v2/options";

describe("onTestMatrixCompleted", () => {
afterEach(() => {
options.setGlobalOptions({});
});

it("should create a function with a handler", () => {
const fn = testLab.onTestMatrixCompleted(() => 2);

expect(fn.__endpoint).to.deep.eq({
platform: "gcfv2",
labels: {},
eventTrigger: {
eventType: testLab.eventType,
eventFilters: {},
retry: false,
},
});
expect(fn.run(1 as any)).to.eq(2);
});

it("should create a function with opts and a handler", () => {
options.setGlobalOptions({
memory: "512MiB",
region: "us-west1",
});

const fn = testLab.onTestMatrixCompleted(
{
region: "us-central1",
retry: true,
},
() => 2
);

expect(fn.__endpoint).to.deep.eq({
platform: "gcfv2",
availableMemoryMb: 512,
region: ["us-central1"],
labels: {},
eventTrigger: {
eventType: testLab.eventType,
eventFilters: {},
retry: true,
},
});
expect(fn.run(1 as any)).to.eq(2);
});
});
2 changes: 2 additions & 0 deletions src/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import * as scheduler from "./providers/scheduler";
import * as storage from "./providers/storage";
import * as tasks from "./providers/tasks";
import * as remoteConfig from "./providers/remoteConfig";
import * as testLab from "./providers/testLab";

export {
alerts,
Expand All @@ -52,6 +53,7 @@ export {
eventarc,
scheduler,
remoteConfig,
testLab,
};

export {
Expand Down
47 changes: 22 additions & 25 deletions src/v2/providers/remoteConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,61 +27,61 @@ import { EventHandlerOptions, getGlobalOptions, optionsToEndpoint } from "../opt
/** @internal */
export const eventType = "google.firebase.remoteconfig.remoteConfig.v1.updated";

/* All the fields associated with the person/service account that wrote a Remote Config template. */
/** All the fields associated with the person/service account that wrote a Remote Config template. */
export interface ConfigUser {
/* Display name. */
/** Display name. */
name: string;

/* Email address. */
/** Email address. */
email: string;

/* Image URL. */
/** Image URL. */
imageUrl: string;
}

/* What type of update was associated with the Remote Config template version. */
/** What type of update was associated with the Remote Config template version. */
export type ConfigUpdateOrigin =
/* Catch-all for unrecognized values. */
/** Catch-all for unrecognized values. */
| "REMOTE_CONFIG_UPDATE_ORIGIN_UNSPECIFIED"
/* The update came from the Firebase UI. */
/** The update came from the Firebase UI. */
| "CONSOLE"
/* The update came from the Remote Config REST API. */
/** The update came from the Remote Config REST API. */
| "REST_API"
/* The update came from the Firebase Admin Node SDK. */
/** The update came from the Firebase Admin Node SDK. */
| "ADMIN_SDK_NODE";

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

/* The data within Firebase Remote Config update events. */
/** The data within Firebase Remote Config update events. */
export interface ConfigUpdateData {
/* The version number of the version's corresponding Remote Config template. */
/** The version number of the version's corresponding Remote Config template. */
versionNumber: number;

/* When the Remote Config template was written to the Remote Config server. */
/** When the Remote Config template was written to the Remote Config server. */
updateTime: string;

/* Aggregation of all metadata fields about the account that performed the update. */
/** Aggregation of all metadata fields about the account that performed the update. */
updateUser: ConfigUser;

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

/* Where the update action originated. */
/** Where the update action originated. */
updateOrigin: ConfigUpdateOrigin;

/* What type of update was made. */
/** What type of update was made. */
updateType: ConfigUpdateType;

/* 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. */
/** 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. */
rollbackSource: number;
}

Expand All @@ -90,7 +90,6 @@ export interface ConfigUpdateData {
*
* @param handler - Event handler which is run every time a Remote Config update occurs.
* @returns A Cloud Function that you can export and deploy.
* @alpha
*/
export function onConfigUpdated(
handler: (event: CloudEvent<ConfigUpdateData>) => any | Promise<any>
Expand All @@ -102,7 +101,6 @@ export function onConfigUpdated(
* @param opts - Options that can be set on an individual event-handling function.
* @param handler - Event handler which is run every time a Remote Config update occurs.
* @returns A Cloud Function that you can export and deploy.
* @alpha
*/
export function onConfigUpdated(
opts: EventHandlerOptions,
Expand All @@ -115,7 +113,6 @@ export function onConfigUpdated(
* @param optsOrHandler - Options or an event handler.
* @param handler - Event handler which is run every time a Remote Config update occurs.
* @returns A Cloud Function that you can export and deploy.
* @alpha
*/
export function onConfigUpdated(
optsOrHandler:
Expand Down
Loading