Skip to content

Remove handler namespace #1196

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 4 commits into from
Aug 23, 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
42 changes: 0 additions & 42 deletions spec/v1/providers/analytics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,48 +290,6 @@ describe("Analytics Functions", () => {
});
});

describe("handler namespace", () => {
describe("#onLog", () => {
it("should return an empty endpoint", () => {
const cloudFunction = functions.handler.analytics.event.onLog(() => null);
expect(cloudFunction.__endpoint).to.be.undefined;
});

it("should handle an event with the appropriate fields", () => {
const cloudFunction = functions.handler.analytics.event.onLog(
(data: analytics.AnalyticsEvent) => data
);

// The event data delivered over the wire will be the JSON for an AnalyticsEvent:
// https://firebase.google.com/docs/auth/admin/manage-users#retrieve_user_data
const event: Event = {
data: {
userDim: {
userId: "hi!",
},
},
context: {
eventId: "70172329041928",
timestamp: "2018-04-09T07:56:12.975Z",
eventType: "providers/google.firebase.analytics/eventTypes/event.log",
resource: {
service: "app-measurement.com",
name: "projects/project1/events/first_open",
},
},
};

return expect(cloudFunction(event.data, event.context)).to.eventually.deep.equal({
params: {},
user: {
userId: "hi!",
userProperties: {},
},
});
});
});
});

describe("process.env.GCLOUD_PROJECT not set", () => {
it("should not throw if __endpoint is not accessed", () => {
expect(() => analytics.event("event").onLog(() => null)).to.not.throw(Error);
Expand Down
27 changes: 0 additions & 27 deletions spec/v1/providers/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,33 +251,6 @@ describe("Auth Functions", () => {
});
});

describe("handler namespace", () => {
describe("#onCreate", () => {
it("should return an empty endpoint", () => {
const cloudFunction = functions.handler.auth.user.onCreate(() => null);
expect(cloudFunction.__endpoint).to.be.undefined;
});
});

describe("#onDelete", () => {
const cloudFunctionDelete: CloudFunction<UserRecord> = functions.handler.auth.user.onDelete(
(data: UserRecord) => data
);

it("should return an empty endpoint", () => {
const cloudFunction = functions.handler.auth.user.onDelete(() => null);
expect(cloudFunction.__endpoint).to.be.undefined;
});

it("should handle wire format as of v5.0.0 of firebase-admin", () => {
return cloudFunctionDelete(event.data, event.context).then((data: any) => {
expect(data.metadata.creationTime).to.equal("2016-12-15T19:37:37.059Z");
expect(data.metadata.lastSignInTime).to.equal("2017-01-01T00:00:00.000Z");
});
});
});
});

describe("process.env.GCLOUD_PROJECT not set", () => {
it("should not throw if __endpoint is not accessed", () => {
expect(() => auth.user().onCreate(() => null)).to.not.throw(Error);
Expand Down
132 changes: 0 additions & 132 deletions spec/v1/providers/database.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,138 +292,6 @@ describe("Database Functions", () => {
});
});

describe("handler namespace", () => {
describe("#onWrite()", () => {
it("correctly sets __endpoint to undefind", () => {
const cf = functions.handler.database.ref.onWrite(() => null);
expect(cf.__endpoint).to.be.undefined;
});

it("should be able to use the instance entry point", () => {
const func = functions.handler.database.instance.ref.onWrite(() => null);
expect(func.__endpoint).to.be.undefined;
});

it("should return a handler that emits events with a proper DataSnapshot", () => {
const event = {
data: {
data: null,
delta: { foo: "bar" },
},
context: {
eventId: "70172329041928",
eventType: "providers/google.firebase.database/eventTypes/ref.write",
timestamp: "2018-04-09T07:56:12.975Z",
resource: "projects/_/instances/subdomains/refs/users",
},
};

const handler = functions.handler.database.ref.onWrite((change) => {
return expect(change.after.val()).to.deep.equal({ foo: "bar" });
});

return handler(event.data, event.context);
});
});

describe("#onCreate()", () => {
it("correctly sets endpoint to undefined", () => {
const cf = functions.handler.database.ref.onCreate(() => null);
expect(cf.__endpoint).to.be.undefined;
});

it("should be able to use the instance entry point", () => {
const func = functions.handler.database.instance.ref.onCreate(() => null);
expect(func.__endpoint).to.be.undefined;
});

it("should return a handler that emits events with a proper DataSnapshot", () => {
const event = {
data: {
data: null,
delta: { foo: "bar" },
},
context: {
eventId: "70172329041928",
eventType: "providers/google.firebase.database/eventTypes/ref.create",
timestamp: "2018-04-09T07:56:12.975Z",
resource: "projects/_/instances/subdomains/refs/users",
},
};
const handler = functions.handler.database.ref.onCreate((data) => {
return expect(data.val()).to.deep.equal({ foo: "bar" });
});

return handler(event.data, event.context);
});
});

describe("#onUpdate()", () => {
it("correctly sets endpoint to undefined", () => {
const cf = functions.handler.database.ref.onUpdate(() => null);
expect(cf.__endpoint).to.be.undefined;
});

it("should be able to use the instance entry point", () => {
const func = functions.handler.database.instance.ref.onUpdate(() => null);
expect(func.__endpoint).to.be.undefined;
});

it("should return a handler that emits events with a proper DataSnapshot", () => {
const event = {
data: {
data: null,
delta: { foo: "bar" },
},
context: {
eventId: "70172329041928",
eventType: "providers/google.firebase.database/eventTypes/ref.update",
timestamp: "2018-04-09T07:56:12.975Z",
resource: "projects/_/instances/subdomains/refs/users",
},
};
const handler = functions.handler.database.ref.onUpdate((change) => {
return expect(change.after.val()).to.deep.equal({ foo: "bar" });
});

return handler(event.data, event.context);
});
});

describe("#onDelete()", () => {
it("correctly sets endpoint to undefined", () => {
const cf = functions.handler.database.ref.onDelete(() => null);
expect(cf.__endpoint).to.be.undefined;
});

it("should be able to use the instance entry point", () => {
const func = functions.handler.database.instance.ref.onDelete(() => null);
expect(func.__endpoint).to.be.undefined;
});

it("should return a handler that emits events with a proper DataSnapshot", () => {
const event = {
data: {
data: { foo: "bar" },
delta: null,
},
context: {
eventId: "70172329041928",
eventType: "providers/google.firebase.database/eventTypes/ref.delete",
timestamp: "2018-04-09T07:56:12.975Z",
resource: "projects/_/instances/subdomains/refs/users",
},
};

const handler = functions.handler.database.ref.onDelete((data) => {
return expect(data.val()).to.deep.equal({ foo: "bar" });
});

return handler(event.data, event.context);
});
});
});

describe("process.env.FIREBASE_CONFIG not set", () => {
it("should not throw if __endpoint is not accessed", () => {
expect(() => database.ref("/path").onWrite(() => null)).to.not.throw(Error);
Expand Down
60 changes: 0 additions & 60 deletions spec/v1/providers/firestore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,66 +250,6 @@ describe("Firestore Functions", () => {
}).timeout(5000);
});

describe("handler namespace", () => {
before(() => {
process.env.GCLOUD_PROJECT = "project1";
});

after(() => {
delete process.env.GCLOUD_PROJECT;
});

it('constructs correct data type on "document.write" events', () => {
const testFunction = functions.handler.firestore.document.onWrite((change) => {
expect(change.before.data()).to.deep.equal({
key1: false,
key2: 111,
});
expect(change.before.get("key1")).to.equal(false);
expect(change.after.data()).to.deep.equal({ key1: true, key2: 123 });
expect(change.after.get("key1")).to.equal(true);
return true; // otherwise will get warning about returning undefined
});
const event = constructEvent(createOldValue(), createValue());
return testFunction(event.data, event.context);
}).timeout(5000);

it('constructs correct data type on "document.create" events', () => {
const testFunction = functions.handler.firestore.document.onCreate((data) => {
expect(data.data()).to.deep.equal({ key1: true, key2: 123 });
expect(data.get("key1")).to.equal(true);
return true; // otherwise will get warning about returning undefined
});
const event = constructEvent({}, createValue());
return testFunction(event.data, event.context);
}).timeout(5000);

it('constructs correct data type on "document.update" events', () => {
const testFunction = functions.handler.firestore.document.onUpdate((change) => {
expect(change.before.data()).to.deep.equal({
key1: false,
key2: 111,
});
expect(change.before.get("key1")).to.equal(false);
expect(change.after.data()).to.deep.equal({ key1: true, key2: 123 });
expect(change.after.get("key1")).to.equal(true);
return true; // otherwise will get warning about returning undefined
});
const event = constructEvent(createOldValue(), createValue());
return testFunction(event.data, event.context);
}).timeout(5000);

it('constructs correct data type on "document.delete" events', () => {
const testFunction = functions.handler.firestore.document.onDelete((data) => {
expect(data.data()).to.deep.equal({ key1: false, key2: 111 });
expect(data.get("key1")).to.equal(false);
return true; // otherwise will get warning about returning undefined
});
const event = constructEvent(createOldValue(), {});
return testFunction(event.data, event.context);
}).timeout(5000);
});

describe("SnapshotConstructor", () => {
describe("#data()", () => {
it("should parse int values", () => {
Expand Down
18 changes: 0 additions & 18 deletions spec/v1/providers/https.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,6 @@ describe("CloudHttpsBuilder", () => {
});
});

describe("handler namespace", () => {
describe("#onRequest", () => {
it("should return an empty trigger", () => {
const result = functions.handler.https.onRequest((req, res) => {
res.send(200);
});
expect(result.__endpoint).to.be.undefined;
});
});

describe("#onCall", () => {
it("should return an empty trigger", () => {
const result = functions.handler.https.onCall(() => null);
expect(result.__endpoint).to.be.undefined;
});
});
});

describe("#onCall", () => {
it("should return a trigger/endpoint with appropriate values", () => {
const result = https.onCall(() => {
Expand Down
74 changes: 0 additions & 74 deletions spec/v1/providers/pubsub.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,80 +306,6 @@ describe("Pubsub Functions", () => {
});
});

describe("handler namespace", () => {
describe("#onPublish", () => {
describe("#topic", () => {
it("should return an empty trigger", () => {
const result = functions.handler.pubsub.topic.onPublish(() => null);
expect(result.__endpoint).to.be.undefined;
});

it("should properly handle a new-style event", () => {
const raw = new Buffer('{"hello":"world"}', "utf8").toString("base64");
const event = {
data: {
data: raw,
attributes: {
foo: "bar",
},
},
context: {
eventId: "70172329041928",
timestamp: "2018-04-09T07:56:12.975Z",
eventType: "google.pubsub.topic.publish",
resource: {
service: "pubsub.googleapis.com",
name: "projects/project1/topics/toppy",
},
},
};

const result = functions.handler.pubsub.topic.onPublish((data) => {
return {
raw: data.data,
json: data.json,
attributes: data.attributes,
};
});

return expect(result(event.data, event.context)).to.eventually.deep.equal({
raw,
json: { hello: "world" },
attributes: { foo: "bar" },
});
});
});
describe("#schedule", () => {
it("should return an empty trigger", () => {
const result = functions.handler.pubsub.schedule.onRun(() => null);
expect(result.__endpoint).to.be.undefined;
});
it("should return a handler with a proper event context", () => {
const raw = new Buffer('{"hello":"world"}', "utf8").toString("base64");
const event = {
data: {
data: raw,
attributes: {
foo: "bar",
},
},
context: {
eventId: "70172329041928",
timestamp: "2018-04-09T07:56:12.975Z",
eventType: "google.pubsub.topic.publish",
resource: {
service: "pubsub.googleapis.com",
name: "projects/project1/topics/toppy",
},
},
};
const result = functions.handler.pubsub.schedule.onRun((context) => context.eventId);
return expect(result(event.data, event.context)).to.eventually.equal("70172329041928");
});
});
});
});

describe("process.env.GCLOUD_PROJECT not set", () => {
it("should not throw if __endpoint is not accessed", () => {
expect(() => pubsub.topic("toppy").onPublish(() => null)).to.not.throw(Error);
Expand Down
Loading