[go: nahoru, domu]

Skip to content
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

Divide everything into v1, v2, and common (unexported). #1149

Merged
merged 11 commits into from
Jun 27, 2022
Prev Previous commit
Merge branch 'launch.next' into inlined.refactor
  • Loading branch information
inlined committed Jun 27, 2022
commit a83ba0d587fa2ad3006ba384c6a794847622d763
4 changes: 2 additions & 2 deletions integration_test/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ function delete_all_functions {
# Try to delete, if there are errors it is because the project is already empty,
# in that case do nothing.
if [[ "${TOKEN}" == "" ]]; then
firebase functions:delete integrationTests v1 v2 --force --project=$PROJECT_ID || : &
firebase functions:delete integration-tests --force --project=$PROJECT_ID || : &
else
firebase functions:delete integrationTests v1 v2 --force --project=$PROJECT_ID --token=$TOKEN || : &
firebase functions:delete integration-tests --force --project=$PROJECT_ID --token=$TOKEN || : &
fi
wait
announce "Project emptied."
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@
"@types/express": "4.17.3",
"cors": "^2.8.5",
"express": "^4.17.1",
"lodash": "^4.17.14",
"node-fetch": "^2.6.7"
},
"devDependencies": {
Expand All @@ -179,7 +178,6 @@
"@types/chai": "^4.1.7",
"@types/chai-as-promised": "^7.1.0",
"@types/jsonwebtoken": "^8.3.2",
"@types/lodash": "^4.14.135",
"@types/mocha": "^5.2.7",
"@types/mock-require": "^2.0.0",
"@types/nock": "^10.0.3",
Expand Down Expand Up @@ -219,4 +217,4 @@
"engines": {
"node": ">=14.10.0"
}
}
}
26 changes: 13 additions & 13 deletions spec/common/providers/https.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect } from 'chai';
import * as firebase from 'firebase-admin';
import { App, deleteApp, initializeApp } from 'firebase-admin/app';
import * as sinon from 'sinon';

import { apps as appsNamespace } from '../../../src/common/apps';
import { getApp, setApp } from '../../../src/common/app';
import * as debug from '../../../src/common/debug';
import * as https from '../../../src/common/providers/https';
import * as mocks from '../../fixtures/credential/key.json';
Expand Down Expand Up @@ -76,7 +76,7 @@ async function runCallableTest(test: CallTest): Promise<any> {
}

describe('onCallHandler', () => {
let app: firebase.app.App;
let app: App;

before(() => {
const credential = {
Expand All @@ -92,16 +92,16 @@ describe('onCallHandler', () => {
};
},
};
app = firebase.initializeApp({
app = initializeApp({
projectId: 'aProjectId',
credential,
});
Object.defineProperty(appsNamespace(), 'admin', { get: () => app });
setApp(app);
});

after(() => {
app.delete();
delete appsNamespace.singleton;
deleteApp(app);
setApp(undefined);
});

it('should handle success', () => {
Expand Down Expand Up @@ -288,7 +288,7 @@ describe('onCallHandler', () => {

it('should handle auth', async () => {
const mock = mockFetchPublicKeys();
const projectId = appsNamespace().admin.options.projectId;
const projectId = getApp().options.projectId;
const idToken = generateIdToken(projectId);
await runCallableTest({
httpRequest: mockRequest(null, 'application/json', {
Expand All @@ -313,7 +313,7 @@ describe('onCallHandler', () => {
});

it('should reject bad auth', async () => {
const projectId = appsNamespace().admin.options.projectId;
const projectId = getApp().options.projectId;
const idToken = generateUnsignedIdToken(projectId);
await runCallableTest({
httpRequest: mockRequest(null, 'application/json', {
Expand Down Expand Up @@ -341,7 +341,7 @@ describe('onCallHandler', () => {

it('should handle AppCheck token', async () => {
const mock = mockFetchAppCheckPublicJwks();
const projectId = appsNamespace().admin.options.projectId;
const projectId = getApp().options.projectId;
const appId = '123:web:abc';
const appCheckToken = generateAppCheckToken(projectId, appId);
await runCallableTest({
Expand All @@ -365,7 +365,7 @@ describe('onCallHandler', () => {
});

it('should reject bad AppCheck token', async () => {
const projectId = appsNamespace().admin.options.projectId;
const projectId = getApp().options.projectId;
const appId = '123:web:abc';
const appCheckToken = generateUnsignedAppCheckToken(projectId, appId);
await runCallableTest({
Expand Down Expand Up @@ -536,7 +536,7 @@ describe('onCallHandler', () => {
});

it('should skip auth token verification', async () => {
const projectId = appsNamespace().admin.options.projectId;
const projectId = getApp().options.projectId;
const idToken = generateUnsignedIdToken(projectId);
await runCallableTest({
httpRequest: mockRequest(null, 'application/json', {
Expand All @@ -560,7 +560,7 @@ describe('onCallHandler', () => {
});

it('should skip app check token verification', async () => {
const projectId = appsNamespace().admin.options.projectId;
const projectId = getApp().options.projectId;
const appId = '123:web:abc';
const appCheckToken = generateUnsignedAppCheckToken(projectId, appId);
await runCallableTest({
Expand Down
18 changes: 9 additions & 9 deletions spec/common/providers/tasks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
// SOFTWARE.

import { expect } from 'chai';
import * as firebase from 'firebase-admin';
import { App, deleteApp, initializeApp } from 'firebase-admin/app';

import { apps as appsNamespace } from '../../../src/common/apps';
import { getApp, setApp } from '../../../src/common/app';
import * as https from '../../../src/common/providers/https';
import {
onDispatchHandler,
Expand Down Expand Up @@ -78,7 +78,7 @@ export async function runTaskTest(test: TaskTest): Promise<any> {
}

describe('onEnqueueHandler', () => {
let app: firebase.app.App;
let app: App;

function mockEnqueueRequest(
data: unknown,
Expand All @@ -102,16 +102,16 @@ describe('onEnqueueHandler', () => {
};
},
};
app = firebase.initializeApp({
app = initializeApp({
projectId: 'aProjectId',
credential,
});
Object.defineProperty(appsNamespace(), 'admin', { get: () => app });
setApp(app);
});

after(() => {
app.delete();
delete appsNamespace.singleton;
deleteApp(app);
setApp(undefined);
});

it('should handle success', () => {
Expand Down Expand Up @@ -201,7 +201,7 @@ describe('onEnqueueHandler', () => {
});

it('should handle auth', async () => {
const projectId = appsNamespace().admin.options.projectId;
const projectId = getApp().options.projectId;
const idToken = generateIdToken(projectId);
await runTaskTest({
httpRequest: mockEnqueueRequest(null, 'application/json', {
Expand All @@ -221,7 +221,7 @@ describe('onEnqueueHandler', () => {
});

it('should accept unsigned auth too', async () => {
const projectId = appsNamespace().admin.options.projectId;
const projectId = getApp().options.projectId;
const idToken = generateUnsignedIdToken(projectId);
await runTaskTest({
httpRequest: mockEnqueueRequest(null, 'application/json', {
Expand Down
3 changes: 1 addition & 2 deletions spec/fixtures/mockrequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as jwt from 'jsonwebtoken';
import * as jwkToPem from 'jwk-to-pem';
import * as _ from 'lodash';
import * as nock from 'nock';
import * as mockJWK from '../fixtures/credential/jwk.json';
import * as mockKey from '../fixtures/credential/key.json';
Expand Down Expand Up @@ -32,7 +31,7 @@ export function mockRequest(
} = {}
) {
const body: any = {};
if (!_.isUndefined(data)) {
if (typeof data !== 'undefined') {
body.data = data;
}

Expand Down
143 changes: 0 additions & 143 deletions spec/v1/apps.spec.ts

This file was deleted.

15 changes: 9 additions & 6 deletions spec/v1/cloud-functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
// SOFTWARE.

import { expect } from 'chai';
import * as _ from 'lodash';

import {
Change,
Expand Down Expand Up @@ -160,9 +159,10 @@ describe('makeCloudFunction', () => {
});

it('should construct the right context for event', () => {
const args: any = _.assign({}, cloudFunctionArgs, {
const args: any = {
...cloudFunctionArgs,
handler: (data: any, context: EventContext) => context,
});
};
const cf = makeCloudFunction(args);
const test: Event = {
context: {
Expand Down Expand Up @@ -190,10 +190,11 @@ describe('makeCloudFunction', () => {
});

it('should throw error when context.params accessed in handler environment', () => {
const args: any = _.assign({}, cloudFunctionArgs, {
const args: any = {
...cloudFunctionArgs,
handler: (data: any, context: EventContext) => context,
triggerResource: () => null,
});
};
const cf = makeCloudFunction(args);
const test: Event = {
context: {
Expand Down Expand Up @@ -413,7 +414,9 @@ describe('Change', () => {

it('should apply the customizer function to `before` and `after`', () => {
function customizer<T>(input: any) {
_.set(input, 'another', 'value');
if (input) {
input.another = 'value';
}
return input as T;
}
const created = Change.fromJSON<object>(
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.