Skip to content

More of annotate endpoint property for functions #1009

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 9 commits into from
Dec 10, 2021
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
5 changes: 5 additions & 0 deletions spec/v1/cloud-functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ describe('makeCloudFunction', () => {
},
retry: false,
},
labels: {},
});
});

Expand All @@ -90,6 +91,7 @@ describe('makeCloudFunction', () => {
},
retry: false,
},
labels: {},
});
});

Expand Down Expand Up @@ -121,6 +123,7 @@ describe('makeCloudFunction', () => {
},
retry: false,
},
labels: {},
});
});

Expand All @@ -143,6 +146,7 @@ describe('makeCloudFunction', () => {
},
retry: true,
},
labels: {},
});
});

Expand All @@ -165,6 +169,7 @@ describe('makeCloudFunction', () => {
expect(cf.__endpoint).to.deep.equal({
platform: 'gcfv1',
scheduleTrigger: schedule,
labels: {},
});
});

Expand Down
22 changes: 20 additions & 2 deletions spec/v1/providers/analytics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ describe('Analytics Functions', () => {
expect(fn.__trigger.regions).to.deep.equal(['us-east1']);
expect(fn.__trigger.availableMemoryMb).to.deep.equal(256);
expect(fn.__trigger.timeout).to.deep.equal('90s');

expect(fn.__endpoint.region).to.deep.equal(['us-east1']);
expect(fn.__endpoint.availableMemoryMb).to.deep.equal(256);
expect(fn.__endpoint.timeoutSeconds).to.deep.equal(90);
});

describe('#onLog', () => {
it('should return a TriggerDefinition with appropriate values', () => {
it('should return a trigger/endpoint with appropriate values', () => {
const cloudFunction = analytics.event('first_open').onLog(() => null);

expect(cloudFunction.__trigger).to.deep.equal({
Expand All @@ -64,6 +68,19 @@ describe('Analytics Functions', () => {
service: 'app-measurement.com',
},
});

expect(cloudFunction.__endpoint).to.deep.equal({
platform: 'gcfv1',
eventTrigger: {
eventFilters: {
resource: 'projects/project1/events/first_open',
},
eventType:
'providers/google.firebase.analytics/eventTypes/event.log',
retry: false,
},
labels: {},
});
});
});

Expand Down Expand Up @@ -305,11 +322,12 @@ describe('Analytics Functions', () => {

describe('handler namespace', () => {
describe('#onLog', () => {
it('should return an empty trigger', () => {
it('should return an empty trigger/endpoint', () => {
const cloudFunction = functions.handler.analytics.event.onLog(
() => null
);
expect(cloudFunction.__trigger).to.deep.equal({});
expect(cloudFunction.__endpoint).to.undefined;
});

it('should handle an event with the appropriate fields', () => {
Expand Down
85 changes: 64 additions & 21 deletions spec/v1/providers/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,38 @@ describe('Auth Functions', () => {
};

describe('AuthBuilder', () => {
function expectedTrigger(project: string, eventType: string) {
return {
eventTrigger: {
resource: `projects/${project}`,
eventType: `providers/firebase.auth/eventTypes/${eventType}`,
service: 'firebaseauth.googleapis.com',
},
};
}

function expectedEndpoint(project: string, eventType: string) {
return {
platform: 'gcfv1',
eventTrigger: {
eventFilters: {
resource: `projects/${project}`,
},
eventType: `providers/firebase.auth/eventTypes/${eventType}`,
retry: false,
},
labels: {},
};
}

const handler = (user: firebase.auth.UserRecord) => {
return Promise.resolve();
};

const project = 'project1';

before(() => {
process.env.GCLOUD_PROJECT = 'project1';
process.env.GCLOUD_PROJECT = project;
});

after(() => {
Expand All @@ -76,31 +102,37 @@ describe('Auth Functions', () => {
expect(fn.__trigger.regions).to.deep.equal(['us-east1']);
expect(fn.__trigger.availableMemoryMb).to.deep.equal(256);
expect(fn.__trigger.timeout).to.deep.equal('90s');

expect(fn.__endpoint.region).to.deep.equal(['us-east1']);
expect(fn.__endpoint.availableMemoryMb).to.deep.equal(256);
expect(fn.__endpoint.timeoutSeconds).to.deep.equal(90);
});

describe('#onCreate', () => {
it('should return a TriggerDefinition with appropriate values', () => {
it('should return a trigger/endpoint with appropriate values', () => {
const cloudFunction = auth.user().onCreate(() => null);
expect(cloudFunction.__trigger).to.deep.equal({
eventTrigger: {
eventType: 'providers/firebase.auth/eventTypes/user.create',
resource: 'projects/project1',
service: 'firebaseauth.googleapis.com',
},
});

expect(cloudFunction.__trigger).to.deep.equal(
expectedTrigger(project, 'user.create')
);

expect(cloudFunction.__endpoint).to.deep.equal(
expectedEndpoint(project, 'user.create')
);
});
});

describe('#onDelete', () => {
it('should return a TriggerDefinition with appropriate values', () => {
it('should return a trigger/endpoint with appropriate values', () => {
const cloudFunction = auth.user().onDelete(handler);
expect(cloudFunction.__trigger).to.deep.equal({
eventTrigger: {
eventType: 'providers/firebase.auth/eventTypes/user.delete',
resource: 'projects/project1',
service: 'firebaseauth.googleapis.com',
},
});

expect(cloudFunction.__trigger).to.deep.equal(
expectedTrigger(project, 'user.delete')
);

expect(cloudFunction.__endpoint).to.deep.equal(
expectedEndpoint(project, 'user.delete')
);
});
});

Expand Down Expand Up @@ -198,6 +230,11 @@ describe('Auth Functions', () => {
const cloudFunction = functions.handler.auth.user.onCreate(() => null);
expect(cloudFunction.__trigger).to.deep.equal({});
});

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

describe('#onDelete', () => {
Expand All @@ -206,13 +243,15 @@ describe('Auth Functions', () => {
);

it('should return an empty trigger', () => {
const handler = (user: firebase.auth.UserRecord) => {
return Promise.resolve();
};
const cloudFunction = functions.handler.auth.user.onDelete(handler);
const cloudFunction = functions.handler.auth.user.onDelete(() => null);
expect(cloudFunction.__trigger).to.deep.equal({});
});

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) => {
Expand All @@ -237,6 +276,10 @@ describe('Auth Functions', () => {
expect(() => auth.user().onCreate(() => null).__trigger).to.throw(Error);
});

it('should throw when endpoint is accessed', () => {
expect(() => auth.user().onCreate(() => null).__endpoint).to.throw(Error);
});

it('should not throw when #run is called', () => {
const cf = auth.user().onCreate(() => null);
expect(cf.run).to.not.throw(Error);
Expand Down
Loading