Skip to content

Commit

Permalink
chore: upgrade firebase to latest version (compat mode)
Browse files Browse the repository at this point in the history
  • Loading branch information
thdk committed Sep 22, 2021
1 parent a971048 commit f8b98e4
Show file tree
Hide file tree
Showing 22 changed files with 1,133 additions and 871 deletions.
528 changes: 390 additions & 138 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@
"peerDependencies": {
"mobx": ">= 6",
"firebase": ">= 8",
"@firebase/rules-unit-testing": "^1.1.4",
"firebase-admin": "^9.2.0"
"@firebase/rules-unit-testing": "^2",
"firebase-admin": "^9"
},
"dependencies": {},
"devDependencies": {
"@firebase/rules-unit-testing": "^1.1.4",
"@firebase/rules-unit-testing": "^2.0.0",
"@rollup/plugin-commonjs": "^16.0.0",
"@rollup/plugin-node-resolve": "^10.0.0",
"@rollup/plugin-typescript": "^6.1.0",
"@testing-library/dom": "^7.28.1",
"@types/jest": "^24.0.23",
"coveralls": "^3.1.0",
"firebase": "^8.10.0",
"firebase": "^9.0.2",
"firebase-admin": "^9.11.1",
"jest": "^26.6.3",
"mobx": "^6.3.3",
Expand Down
2 changes: 1 addition & 1 deletion src/__test-utils__/firestore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type firebase from "firebase";
import type firebase from "firebase/compat";

export const addAsync = <T>(
collectionRef: firebase.firestore.CollectionReference,
Expand Down
62 changes: 33 additions & 29 deletions src/collection/__tests__/add-document.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
import { firestore as firestoreNamespace } from "firebase-admin";
import { initializeTestEnvironment, RulesTestEnvironment } from "@firebase/rules-unit-testing";
import { ICollectionOptions, Collection } from "../..";
import { initTestFirestore } from "../../../utils/test-firestore";
import { logger } from "../../__test-utils__";

const firebase = require("firebase-admin");

const {
firestore,
refs: [collectionRef],
clearFirestoreData,
deleteFirebaseApp,
} = initTestFirestore(
"test-add-documents",
["books"],
);
import firebase from "firebase/compat";

interface IBook {
name: string;
Expand All @@ -22,24 +11,39 @@ interface IBook {
isDeleted?: boolean;
}

export function createCollection<T, K = T>(options?: ICollectionOptions<T, K>) {
return new Collection<T, K>(
firestore,
collectionRef,
options,
{
logger
}
);
}
describe("Collection.addAsync", () => {
let testEnv: RulesTestEnvironment;
let collection: Collection<IBook>;
let collectionRef: firebase.firestore.CollectionReference;
let firestore: firebase.firestore.Firestore;

let collection: Collection<IBook>;
function createCollection<T, K = T>(options?: ICollectionOptions<T, K>) {
return new Collection<T, K>(
firestore,
collectionRef,
options,
{
logger
}
);
}

beforeEach(() => clearFirestoreData());
beforeEach(() => testEnv.clearFirestore());

afterAll(deleteFirebaseApp);
afterAll(() => testEnv.cleanup());
beforeAll(async () => {
testEnv = await initializeTestEnvironment({
projectId: "test-add-documents",
firestore: {
host: "localhost",
port: 8080,
}
});

firestore = testEnv.unauthenticatedContext().firestore();
collectionRef = firestore.collection("books");
});

describe("Collection.addAsync", () => {
beforeEach(() => {
collection = createCollection<IBook>({
serialize: data => {
Expand Down Expand Up @@ -69,7 +73,7 @@ describe("Collection.addAsync", () => {
})
.then(id => {
return collectionRef.doc(id).get()
.then((snapshot: firestoreNamespace.DocumentSnapshot) => {
.then(snapshot => {
expect(snapshot.exists).toBe(true);
});
});
Expand All @@ -88,7 +92,7 @@ describe("Collection.addAsync", () => {
)
.then(() => {
return collectionRef.doc("given-id").get()
.then((snapshot: firestoreNamespace.DocumentSnapshot) => {
.then(snapshot => {
expect(snapshot.exists).toBe(true);
});
});
Expand Down
25 changes: 18 additions & 7 deletions src/collection/__tests__/constructor.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import { initializeTestEnvironment, RulesTestEnvironment } from "@firebase/rules-unit-testing";
import { Collection } from "../..";

import { initTestFirestore } from "../../../utils/test-firestore";
import type firebase from "firebase/compat";

const {
firestore,
} = initTestFirestore(
"test-constructor-collection",
["books"],
);

const projectId = "test-constructor-collection";
describe("Collection.constructor", () => {
let firestore: firebase.firestore.Firestore;
let testEnv: RulesTestEnvironment;

beforeAll(async () => {
testEnv = await initializeTestEnvironment({
projectId,
firestore: {
host: "localhost",
port: 8080,
}
});

firestore = testEnv.unauthenticatedContext().firestore();
});

test("it should create a Collection instance with a string as collectionRef", () => {
const collection = new Collection(firestore, "books");

Expand Down
64 changes: 36 additions & 28 deletions src/collection/__tests__/delete-documents.test.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
import { firestore } from "firebase-admin";
import { initializeTestEnvironment, RulesTestEnvironment } from "@firebase/rules-unit-testing";
import { Collection, ICollectionOptions, RealtimeMode } from "../..";
import { initTestFirestore } from "../../../utils/test-firestore";
import { logger } from "../../__test-utils__";

const {
firestore: firestoreDb,
refs: [collectionRef],
clearFirestoreData,
deleteFirebaseApp,
} = initTestFirestore(
"test-delete-documents",
["books"]
);
import type firebase from "firebase/compat";

export function createCollection<T, K = T>(options?: ICollectionOptions<T, K>) {
return new Collection<T, K>(
firestoreDb,
collectionRef,
options,
{
logger: logger
}
);
}
const projectId = "test-delete-documents";
describe("Collection.deleteAsync", () => {
let collectionRef: firebase.firestore.CollectionReference;
let firestore: firebase.firestore.Firestore;
let testEnv: RulesTestEnvironment;

beforeAll(async () => {
testEnv = await initializeTestEnvironment({
projectId,
firestore: {
host: "localhost",
port: 8080,
}
});

beforeEach(() => clearFirestoreData());
firestore = testEnv.unauthenticatedContext().firestore();
collectionRef = firestore.collection("books");
});

afterAll(deleteFirebaseApp);

describe("Collection.deleteAsync", () => {
function createCollection<T, K = T>(options?: ICollectionOptions<T, K>) {
return new Collection<T, K>(
firestore,
collectionRef,
options,
{
logger: logger
}
);
}

afterAll(() => testEnv.cleanup());

beforeEach(() => {
beforeEach(async () => {
await testEnv.clearFirestore()
// Add initial data
return Promise.all([
collectionRef.doc("id1").set({ total: 1, name: "A" }),
Expand All @@ -41,19 +49,19 @@ describe("Collection.deleteAsync", () => {
});

describe("when collection is not filtered with a query", () => {
test("it should delete the document with the given id", () => {
it("should delete the document with the given id", () => {
const collection = createCollection({ realtimeMode: RealtimeMode.off });

return collection.deleteAsync("id2")
.then(() => {
return collectionRef.doc("id2").get()
.then((doc: firestore.DocumentSnapshot) => {
.then(doc => {
expect(doc.exists).toBe(false);
});
});
});

test("it should delete multiple documents", () => {
it("should delete multiple documents", () => {
const collection = createCollection();

return collection.deleteAsync("id2", "id3")
Expand Down
Loading

0 comments on commit f8b98e4

Please sign in to comment.