Skip to content

More ESLint Migration #1197

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 2 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
18 changes: 9 additions & 9 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
coverage
dev
lib
dev
node_modules
docgen
v1
v2
logger
dist
spec/fixtures
scripts/**/*.js
/coverage/
/docgen/
/v1/
/v2/
/logger/
/dist/
/spec/fixtures
/scripts/**/*.js
68 changes: 25 additions & 43 deletions integration_test/functions/src/v1/auth-tests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';
import { REGION } from '../region';
import { expectEq, TestSuite } from '../testing';
import * as admin from "firebase-admin";
import * as functions from "firebase-functions";
import { REGION } from "../region";
import { expectEq, TestSuite } from "../testing";
import UserMetadata = admin.auth.UserRecord;

export const createUserTests: any = functions
Expand All @@ -11,35 +11,26 @@ export const createUserTests: any = functions
const testId: string = u.displayName;
functions.logger.info(`testId is ${testId}`);

return new TestSuite<UserMetadata>('auth user onCreate')
.it('should have a project as resource', (user, context) =>
expectEq(
context.resource.name,
`projects/${process.env.GCLOUD_PROJECT}`
)
return new TestSuite<UserMetadata>("auth user onCreate")
.it("should have a project as resource", (user, context) =>
expectEq(context.resource.name, `projects/${process.env.GCLOUD_PROJECT}`)
)

.it('should not have a path', (user, context) =>
expectEq((context as any).path, undefined)
)
.it("should not have a path", (user, context) => expectEq((context as any).path, undefined))

.it('should have the correct eventType', (user, context) =>
expectEq(context.eventType, 'google.firebase.auth.user.create')
.it("should have the correct eventType", (user, context) =>
expectEq(context.eventType, "google.firebase.auth.user.create")
)

.it('should have an eventId', (user, context) => context.eventId)
.it("should have an eventId", (user, context) => context.eventId)

.it('should have a timestamp', (user, context) => context.timestamp)
.it("should have a timestamp", (user, context) => context.timestamp)

.it('should not have auth', (user, context) =>
expectEq((context as any).auth, undefined)
)
.it("should not have auth", (user, context) => expectEq((context as any).auth, undefined))

.it('should not have action', (user, context) =>
expectEq((context as any).action, undefined)
)
.it("should not have action", (user, context) => expectEq((context as any).action, undefined))

.it('should have properly defined meta', (user, context) => user.metadata)
.it("should have properly defined meta", (user) => user.metadata)

.run(testId, u, c);
});
Expand All @@ -51,33 +42,24 @@ export const deleteUserTests: any = functions
const testId: string = u.displayName;
functions.logger.info(`testId is ${testId}`);

return new TestSuite<UserMetadata>('auth user onDelete')
.it('should have a project as resource', (user, context) =>
expectEq(
context.resource.name,
`projects/${process.env.GCLOUD_PROJECT}`
)
return new TestSuite<UserMetadata>("auth user onDelete")
.it("should have a project as resource", (user, context) =>
expectEq(context.resource.name, `projects/${process.env.GCLOUD_PROJECT}`)
)

.it('should not have a path', (user, context) =>
expectEq((context as any).path, undefined)
)
.it("should not have a path", (user, context) => expectEq((context as any).path, undefined))

.it('should have the correct eventType', (user, context) =>
expectEq(context.eventType, 'google.firebase.auth.user.delete')
.it("should have the correct eventType", (user, context) =>
expectEq(context.eventType, "google.firebase.auth.user.delete")
)

.it('should have an eventId', (user, context) => context.eventId)
.it("should have an eventId", (user, context) => context.eventId)

.it('should have a timestamp', (user, context) => context.timestamp)
.it("should have a timestamp", (user, context) => context.timestamp)

.it('should not have auth', (user, context) =>
expectEq((context as any).auth, undefined)
)
.it("should not have auth", (user, context) => expectEq((context as any).auth, undefined))

.it('should not have action', (user, context) =>
expectEq((context as any).action, undefined)
)
.it("should not have action", (user, context) => expectEq((context as any).action, undefined))

.run(testId, u, c);
});
47 changes: 20 additions & 27 deletions integration_test/functions/src/v1/database-tests.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';
import { REGION } from '../region';
import { expectEq, expectMatches, TestSuite } from '../testing';
import * as admin from "firebase-admin";
import * as functions from "firebase-functions";
import { REGION } from "../region";
import { expectEq, expectMatches, TestSuite } from "../testing";
import DataSnapshot = admin.database.DataSnapshot;

const testIdFieldName = 'testId';
const testIdFieldName = "testId";

export const databaseTests: any = functions
.region(REGION)
.database.ref('dbTests/{testId}/start')
.database.ref("dbTests/{testId}/start")
.onWrite((ch, ctx) => {
if (ch.after.val() === null) {
functions.logger.info(
'Event for ' +
ctx.params[testIdFieldName] +
' is null; presuming data cleanup, so skipping.'
`Event for ${ctx.params[testIdFieldName]} is null; presuming data cleanup, so skipping.`
);
return;
}

return new TestSuite<functions.Change<DataSnapshot>>('database ref onWrite')
return new TestSuite<functions.Change<DataSnapshot>>("database ref onWrite")

.it(
'should not have event.app',
(change, context) => !(context as any).app
)
.it("should not have event.app", (change, context) => !(context as any).app)

.it('should give refs access to admin data', (change) =>
.it("should give refs access to admin data", (change) =>
change.after.ref.parent
.child('adminOnly')
.child("adminOnly")
.update({ allowed: 1 })
.then(() => true)
)

.it('should have a correct ref url', (change) => {
.it("should have a correct ref url", (change) => {
const url = change.after.ref.toString();
return Promise.resolve()
.then(() => {
Expand All @@ -49,7 +44,7 @@ export const databaseTests: any = functions
});
})

.it('should have refs resources', (change, context) =>
.it("should have refs resources", (change, context) =>
expectMatches(
context.resource.name,
new RegExp(
Expand All @@ -58,25 +53,23 @@ export const databaseTests: any = functions
)
)

.it('should not include path', (change, context) =>
.it("should not include path", (change, context) =>
expectEq((context as any).path, undefined)
)

.it('should have the right eventType', (change, context) =>
expectEq(context.eventType, 'google.firebase.database.ref.write')
.it("should have the right eventType", (change, context) =>
expectEq(context.eventType, "google.firebase.database.ref.write")
)

.it('should have eventId', (change, context) => context.eventId)
.it("should have eventId", (change, context) => context.eventId)

.it('should have timestamp', (change, context) => context.timestamp)
.it("should have timestamp", (change, context) => context.timestamp)

.it('should not have action', (change, context) =>
.it("should not have action", (change, context) =>
expectEq((context as any).action, undefined)
)

.it('should have admin authType', (change, context) =>
expectEq(context.authType, 'ADMIN')
)
.it("should have admin authType", (change, context) => expectEq(context.authType, "ADMIN"))

.run(ctx.params[testIdFieldName], ch, ctx);
});
30 changes: 15 additions & 15 deletions integration_test/functions/src/v1/firestore-tests.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';
import { REGION } from '../region';
import { expectDeepEq, expectEq, TestSuite } from '../testing';
import * as admin from "firebase-admin";
import * as functions from "firebase-functions";
import { REGION } from "../region";
import { expectDeepEq, expectEq, TestSuite } from "../testing";
import DocumentSnapshot = admin.firestore.DocumentSnapshot;

const testIdFieldName = 'documentId';
const testIdFieldName = "documentId";

export const firestoreTests: any = functions
.runWith({
timeoutSeconds: 540,
})
.region(REGION)
.firestore.document('tests/{documentId}')
.firestore.document("tests/{documentId}")
.onCreate((s, c) => {
return new TestSuite<DocumentSnapshot>('firestore document onWrite')
return new TestSuite<DocumentSnapshot>("firestore document onWrite")

.it('should not have event.app', (snap, context) => !(context as any).app)
.it("should not have event.app", (snap, context) => !(context as any).app)

.it('should give refs write access', (snap) =>
.it("should give refs write access", (snap) =>
snap.ref.set({ allowed: 1 }, { merge: true }).then(() => true)
)

.it('should have well-formatted resource', (snap, context) =>
.it("should have well-formatted resource", (snap, context) =>
expectEq(
context.resource.name,
`projects/${process.env.GCLOUD_PROJECT}/databases/(default)/documents/tests/${context.params.documentId}`
)
)

.it('should have the right eventType', (snap, context) =>
expectEq(context.eventType, 'google.firestore.document.create')
.it("should have the right eventType", (snap, context) =>
expectEq(context.eventType, "google.firestore.document.create")
)

.it('should have eventId', (snap, context) => context.eventId)
.it("should have eventId", (snap, context) => context.eventId)

.it('should have timestamp', (snap, context) => context.timestamp)
.it("should have timestamp", (snap, context) => context.timestamp)

.it('should have the correct data', (snap, context) =>
.it("should have the correct data", (snap, context) =>
expectDeepEq(snap.data(), { test: context.params.documentId })
)

Expand Down
14 changes: 6 additions & 8 deletions integration_test/functions/src/v1/https-tests.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import * as functions from 'firebase-functions';
import { REGION } from '../region';
import { expectEq, TestSuite } from '../testing';
import * as functions from "firebase-functions";
import { REGION } from "../region";
import { expectEq, TestSuite } from "../testing";

export const callableTests: any = functions
.runWith({ invoker: 'private' })
.runWith({ invoker: "private" })
.region(REGION)
.https.onCall((d) => {
return new TestSuite('https onCall')
.it('should have the correct data', (data: any) =>
expectEq(data?.foo, 'bar')
)
return new TestSuite("https onCall")
.it("should have the correct data", (data: any) => expectEq(data?.foo, "bar"))
.run(d.testId, d);
});
16 changes: 8 additions & 8 deletions integration_test/functions/src/v1/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export * from './pubsub-tests';
export * from './database-tests';
export * from './auth-tests';
export * from './firestore-tests';
export * from './https-tests';
export * from './remoteConfig-tests';
export * from './storage-tests';
export * from './testLab-tests';
export * from "./pubsub-tests";
export * from "./database-tests";
export * from "./auth-tests";
export * from "./firestore-tests";
export * from "./https-tests";
export * from "./remoteConfig-tests";
export * from "./storage-tests";
export * from "./testLab-tests";
Loading