Skip to content

Instantly share code, notes, and snippets.

@bezysoftware
Last active June 16, 2017 13:09
Show Gist options
  • Select an option

  • Save bezysoftware/67942bcd281c018a4675059957376f6d to your computer and use it in GitHub Desktop.

Select an option

Save bezysoftware/67942bcd281c018a4675059957376f6d to your computer and use it in GitHub Desktop.
import * as mocha from 'mocha'
import * as sinon from 'sinon'
import * as admin from 'firebase-admin'
import * as changes from '../changes'
import { expect } from 'chai'
import { Event } from 'firebase-functions';
import { DeltaSnapshot } from 'firebase-functions/lib/providers/database';
describe("Change", () => {
let refStub = sinon.stub().returns({
root: {
child: sinon.stub().returns({
push: sinon.stub().returns({
set: sinon.stub()
})
})
}
});
function createEvent(data, diff) {
let event: Event<DeltaSnapshot> | UndocumentedEvent = {
data: new DeltaSnapshot(null, null, data, diff, null),
auth: {
variable: {
uid: "123"
}
},
params: {
entityId: "entity",
groupId: "group"
}
} as Event<DeltaSnapshot>;
Object.defineProperty(event.data, 'adminRef', { get: refStub });
Object.defineProperty(event.data, 'ref', { get: refStub });
return event;
}
function createChange(action: string, entity: string) : Change {
return {
action: action,
by: "123",
entity: entity,
entityId: "entity"
};
}
it("should be correctly generated for new expense", async () => {
let tx: Transaction = {
currencyCode: 'USD',
purpose: "test tx",
exchangeRates: {
"USD": "1.0"
},
type: "expense"
};
let event = createEvent(null, tx);
let change = await changes.writeTransactionChange(event);
let expected = createChange(changes.ACTION_INSERT, changes.ENTITY_EXPENSE);
expect(change).to.eql(expected);
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment