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

refactor(firebase):ava to mocha #1158

Merged
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
4 changes: 2 additions & 2 deletions functions/firebase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"node": ">=8"
},
"scripts": {
"test": "ava -T 30s test/*.test.js"
"test": "mocha test/*.test.js --timeout=30000"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"ava": "0.25.0",
"mocha": "^5.2.0",
"proxyquire": "2.1.0",
"sinon": "7.2.5",
"supertest": "^3.0.0",
Expand Down
83 changes: 52 additions & 31 deletions functions/firebase/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

'use strict';

const proxyquire = require(`proxyquire`).noCallThru();
const sinon = require(`sinon`);
const test = require(`ava`);
const tools = require(`@google-cloud/nodejs-repo-tools`);
const proxyquire = require('proxyquire').noCallThru();
const sinon = require('sinon');
const assert = require('assert');
const tools = require('@google-cloud/nodejs-repo-tools');

function getSample() {
const firestoreMock = {
Expand All @@ -27,7 +27,7 @@ function getSample() {
};

return {
program: proxyquire(`../`, {
program: proxyquire('../', {
'@google-cloud/firestore': sinon.stub().returns(firestoreMock),
}),
mocks: {
Expand All @@ -36,10 +36,10 @@ function getSample() {
};
}

test.beforeEach(tools.stubConsole);
test.afterEach.always(tools.restoreConsole);
beforeEach(tools.stubConsole);
afterEach(tools.restoreConsole);

test(`should listen to RTDB`, t => {
it('should listen to RTDB', () => {
const sample = getSample();

const delta = {
Expand All @@ -55,12 +55,18 @@ test(`should listen to RTDB`, t => {

sample.program.helloRTDB(event);

t.true(console.log.calledWith(`Function triggered by change to: resource`));
t.true(console.log.calledWith(`Admin?: true`));
t.true(console.log.calledWith(JSON.stringify(delta, null, 2)));
assert.strictEqual(
console.log.calledWith('Function triggered by change to: resource'),
true
);
assert.strictEqual(console.log.calledWith('Admin?: true'), true);
assert.strictEqual(
console.log.calledWith(JSON.stringify(delta, null, 2)),
true
);
});

test(`should listen to Firestore`, t => {
it('should listen to Firestore', () => {
const sample = getSample();

const oldValue = {
Expand All @@ -80,13 +86,22 @@ test(`should listen to Firestore`, t => {

sample.program.helloFirestore(event);

t.true(console.log.calledWith(`Function triggered by event on: resource`));
t.true(console.log.calledWith(`Event type: type`));
t.true(console.log.calledWith(JSON.stringify(oldValue, null, 2)));
t.true(console.log.calledWith(JSON.stringify(value, null, 2)));
assert.strictEqual(
console.log.calledWith('Function triggered by event on: resource'),
true
);
assert.strictEqual(console.log.calledWith('Event type: type'), true);
assert.strictEqual(
console.log.calledWith(JSON.stringify(oldValue, null, 2)),
true
);
assert.strictEqual(
console.log.calledWith(JSON.stringify(value, null, 2)),
true
);
});

test(`should listen to Auth events`, t => {
it('should listen to Auth events', () => {
const sample = getSample();
const date = Date.now();
const event = {
Expand All @@ -102,12 +117,15 @@ test(`should listen to Auth events`, t => {

sample.program.helloAuth(event);

t.true(console.log.calledWith(`Function triggered by change to user: me`));
t.true(console.log.calledWith(`Created at: ${date}`));
t.true(console.log.calledWith(`Email: me@example.com`));
assert.strictEqual(
console.log.calledWith('Function triggered by change to user: me'),
true
);
assert.strictEqual(console.log.calledWith(`Created at: ${date}`), true);
assert.strictEqual(console.log.calledWith('Email: me@example.com'), true);
});

test.serial('should listen to Analytics events', t => {
it('should listen to Analytics events', () => {
const date = new Date();
const event = {
data: {
Expand All @@ -132,17 +150,17 @@ test.serial('should listen to Analytics events', t => {

const sample = getSample();
sample.program.helloAnalytics(event);
t.is(
assert.strictEqual(
console.log.args[0][0],
`Function triggered by the following event: my-resource`
'Function triggered by the following event: my-resource'
);
t.is(console.log.args[1][0], `Name: my-event`);
t.is(console.log.args[2][0], `Timestamp: ${date}`);
t.is(console.log.args[3][0], `Device Model: Pixel`);
t.is(console.log.args[4][0], `Location: London, UK`);
assert.strictEqual(console.log.args[1][0], 'Name: my-event');
assert.strictEqual(console.log.args[2][0], `Timestamp: ${date}`);
assert.strictEqual(console.log.args[3][0], 'Device Model: Pixel');
assert.strictEqual(console.log.args[4][0], 'Location: London, UK');
});

test(`should listen to Remote Config events`, t => {
it('should listen to Remote Config events', () => {
const sample = getSample();

const event = {
Expand All @@ -155,7 +173,10 @@ test(`should listen to Remote Config events`, t => {

sample.program.helloRemoteConfig(event);

t.true(console.log.calledWith(`Update type: INCREMENTAL_UPDATE`));
t.true(console.log.calledWith(`Origin: CONSOLE`));
t.true(console.log.calledWith(`Version: 1`));
assert.strictEqual(
console.log.calledWith('Update type: INCREMENTAL_UPDATE'),
true
);
assert.strictEqual(console.log.calledWith('Origin: CONSOLE'), true);
assert.strictEqual(console.log.calledWith('Version: 1'), true);
});