Skip to content

Commit

Permalink
add oninit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
blidd-google committed Apr 3, 2024
1 parent 3902b80 commit 7836601
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 7 deletions.
68 changes: 68 additions & 0 deletions spec/v2/providers/firestore.spec.ts
Expand Up @@ -565,6 +565,23 @@ describe("firestore", () => {
expect(func.run(true as any)).to.eq(2);
expect(func.__endpoint).to.deep.eq(expectedEp);
});

it("calls init function", async () => {
const event: firestore.RawFirestoreEvent = {
...eventBase,
datacontenttype: "application/json",
data: {
oldValue: null,
value: null,
},
};

let hello;
onInit(() => (hello = "world"));
expect(hello).to.be.undefined;
await firestore.onDocumentWrittenWithAuthContext("path", () => null)(event);
expect(hello).to.equal("world");
});
});

describe("onDocumentCreatedWithAuthContext", () => {
Expand Down Expand Up @@ -612,6 +629,23 @@ describe("firestore", () => {
expect(func.run(true as any)).to.eq(2);
expect(func.__endpoint).to.deep.eq(expectedEp);
});

it("calls init function", async () => {
const event: firestore.RawFirestoreEvent = {
...eventBase,
datacontenttype: "application/json",
data: {
oldValue: null,
value: null,
},
};

let hello;
onInit(() => (hello = "world"));
expect(hello).to.be.undefined;
await firestore.onDocumentCreatedWithAuthContext("path", () => null)(event);
expect(hello).to.equal("world");
});
});

describe("onDocumentUpdatedWithAuthContext", () => {
Expand Down Expand Up @@ -659,6 +693,23 @@ describe("firestore", () => {
expect(func.run(true as any)).to.eq(2);
expect(func.__endpoint).to.deep.eq(expectedEp);
});

it("calls init function", async () => {
const event: firestore.RawFirestoreEvent = {
...eventBase,
datacontenttype: "application/json",
data: {
oldValue: null,
value: null,
},
};

let hello;
onInit(() => (hello = "world"));
expect(hello).to.be.undefined;
await firestore.onDocumentUpdatedWithAuthContext("path", () => null)(event);
expect(hello).to.equal("world");
});
});

describe("onDocumentDeletedWithAuthContext", () => {
Expand Down Expand Up @@ -706,6 +757,23 @@ describe("firestore", () => {
expect(func.run(true as any)).to.eq(2);
expect(func.__endpoint).to.deep.eq(expectedEp);
});

it("calls init function", async () => {
const event: firestore.RawFirestoreEvent = {
...eventBase,
datacontenttype: "application/json",
data: {
oldValue: null,
value: null,
},
};

let hello;
onInit(() => (hello = "world"));
expect(hello).to.be.undefined;
await firestore.onDocumentDeletedWithAuthContext("path", () => null)(event);
expect(hello).to.equal("world");
});
});

describe("getOpts", () => {
Expand Down
7 changes: 0 additions & 7 deletions src/v2/providers/firestore.ts
Expand Up @@ -236,13 +236,6 @@ export function onDocumentWrittenWithAuthContext<Document extends string>(
event: FirestoreAuthEvent<Change<DocumentSnapshot> | undefined, ParamsOf<Document>>
) => any | Promise<any>
): CloudFunction<FirestoreAuthEvent<Change<DocumentSnapshot> | undefined, ParamsOf<Document>>> {
// const fn = (
// event: FirestoreEvent<Change<QueryDocumentSnapshot> | undefined, ParamsOf<Document>> & {
// foo: string;
// }
// ): any => {
// return event;
// };
return onChangedOperation(writtenEventWithAuthContextType, documentOrOpts, handler);
}

Expand Down

0 comments on commit 7836601

Please sign in to comment.