Skip to content

Commit

Permalink
Add Firestore to test unit
Browse files Browse the repository at this point in the history
  • Loading branch information
GogoVega committed Aug 20, 2024
1 parent cbc1a86 commit 9ed37e3
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ jobs:
env:
API_KEY: ${{ secrets.API_KEY }}
RTDB_URL: ${{ secrets.RTDB_URL }}
PROJECT_ID: ${{ secrets.PROJECT_ID }}
70 changes: 68 additions & 2 deletions test/firebase-config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

const database = require("../build");
const { Client } = require("../build/lib/firebase/client");
const { Firestore } = require("../build/lib/firebase/firestore");
const { RTDB } = require("../build/lib/firebase/rtdb");

const helper = require("node-red-node-test-helper");
const should = require('should');

const apiKey = process.env.API_KEY;
const url = process.env.RTDB_URL;
const projectId = process.env.PROJECT_ID;

// TODO: Add more tests
describe("Firebase Config Node", function () {
Expand Down Expand Up @@ -154,9 +156,9 @@ describe("Firebase Config Node", function () {
});

context("When the database is used", () => {
const creds = { apiKey: apiKey, url: url };
const creds = { apiKey: apiKey, url: url, projectId: projectId };

it("should have initialised the rtdb", function (done) {
it("should have initialised the RTDB", function (done) {
const flow = [{ id: "database", type: "firebase-config", name: "My Database", authType: "anonymous" }];

helper.load([database], flow, { "database": creds }, function () {
Expand All @@ -176,6 +178,48 @@ describe("Firebase Config Node", function () {
});
});

it("should have initialised Firestore", function (done) {
const flow = [{ id: "database", type: "firebase-config", name: "My Database", authType: "anonymous" }];

helper.load([database], flow, { "database": creds }, function () {
try {
const n1 = helper.getNode("database");

n1.addStatusListener("fake-node", "firestore");
n1.addStatusListener.should.have.been.called;

n1.firestore.should.be.Object();
n1.firestore.should.be.instanceOf(Firestore);

done();
} catch (error) {
done(error);
}
});
});

it("should have initialised both RTDB and Firestore", function (done) {
const flow = [{ id: "database", type: "firebase-config", name: "My Database", authType: "anonymous", status: { firestore: true } }];

helper.load([database], flow, { "database": creds }, function () {
try {
const n1 = helper.getNode("database");

n1.addStatusListener("fake-node", "firestore");
n1.addStatusListener.should.have.been.called;

n1.rtdb.should.be.Object();
n1.rtdb.should.be.instanceOf(RTDB);
n1.firestore.should.be.Object();
n1.firestore.should.be.instanceOf(Firestore);

done();
} catch (error) {
done(error);
}
});
});

it("should triggers the connection events", function (done) {
const flow = [{ id: "database", type: "firebase-config", name: "My Database", authType: "anonymous" }];

Expand Down Expand Up @@ -238,4 +282,26 @@ describe("Firebase Config Node", function () {
});
});
});

context("When the config-node is closed", function () {
it("should signOut and delete App", function (done) {
const flow = [{ id: "database", type: "firebase-config", name: "My Database", authType: "anonymous" }];

helper.load([database], flow, function () {
try {
const n1 = helper.getNode("database");

n1.close(true)
.then(() => {
n1.client.signOut.should.have.been.called;
n1.client._app.deleteApp.should.have.been.called;
done();
})
.catch((error) => done(error));
} catch (error) {
done(error);
}
});
});
});
});

0 comments on commit 9ed37e3

Please sign in to comment.