Skip to content

Commit 6d4d6d3

Browse files
committed
code fixes and refactoring based on pull request comments
1 parent 8515b3e commit 6d4d6d3

File tree

9 files changed

+37
-54
lines changed

9 files changed

+37
-54
lines changed

functions/.env.example.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

functions/env.example.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"databaseURL": "",
3+
"storageBucket": "",
4+
"projectId": "",
5+
"serviceAccountKey": ""
6+
}

functions/env.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

functions/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
},
1717
"main": "lib/index.js",
1818
"dependencies": {
19-
"chai": "^4.2.0",
2019
"chai-as-promised": "^7.1.1",
2120
"firebase-admin": "^8.12.1",
2221
"firebase-functions": "^3.6.2",
Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,32 @@
1-
import { admin, test } from '../../util/admin';
1+
import { admin, test } from '../../util/config';
22
import * as chai from 'chai';
33
import * as chaiAsPromised from 'chai-as-promised';
4-
import * as onDelete from '../../../src/db/users/onDelete.function';
4+
import onDelete from '../../../src/db/users/onDelete.function';
55
import 'mocha';
66

77
chai.use(chaiAsPromised);
88

99
describe('onDelete', () => {
1010
let userRecord: any;
1111

12-
before(async () => {
13-
const user = {
14-
uid: '1234',
15-
email: 'user@example.com',
16-
password: 'secretPassword'
17-
};
18-
userRecord = await admin.auth().createUser(user);
19-
});
12+
it('should delete the user from the authentication section', async () => {
13+
userRecord = await admin.auth().createUser({ email: 'user@example.com' });
2014

21-
it('should delete the user from the authentication section', () => {
22-
const wrapped = test.wrap(onDelete.default);
15+
const wrapped = test.wrap(onDelete);
2316

24-
return wrapped(
17+
await wrapped(
2518
{},
2619
{
2720
params: {
2821
uid: userRecord.uid
2922
}
3023
}
31-
).then(async () => {
32-
await chai
33-
.expect(admin.auth().getUser(userRecord.uid))
34-
.to.be.rejectedWith(
35-
Error,
36-
'There is no user record corresponding to the provided identifier.'
37-
);
38-
});
24+
);
25+
return await chai
26+
.expect(admin.auth().getUser(userRecord.uid))
27+
.to.be.rejectedWith(
28+
Error,
29+
'There is no user record corresponding to the provided identifier.'
30+
);
3931
});
4032
});

functions/test/db/users/onUpdate.test.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import { admin, test } from '../../util/admin';
1+
import { admin, test } from '../../util/config';
22
import * as chai from 'chai';
3-
import * as onUpdate from '../../../src/db/users/onUpdate.function';
3+
import onUpdate from '../../../src/db/users/onUpdate.function';
44
import 'mocha';
55

66
describe('onUpdate', () => {
77
let userRecord: any;
88

99
before(async () => {
1010
const user = {
11-
uid: '1234',
1211
email: 'user@example.com',
1312
password: 'secretPassword'
1413
};
@@ -25,8 +24,8 @@ describe('onUpdate', () => {
2524
test.cleanup();
2625
});
2726

28-
it('should update the user information in the database', () => {
29-
const wrapped = test.wrap(onUpdate.default);
27+
it("should update user's custom claims in auth", async () => {
28+
const wrapped = test.wrap(onUpdate);
3029

3130
const beforeSnap = test.database.makeDataSnapshot(
3231
{ email: 'user@example.com', isAdmin: false },
@@ -39,17 +38,16 @@ describe('onUpdate', () => {
3938

4039
const change = test.makeChange(beforeSnap, afterSnap);
4140

42-
return wrapped(change, {
41+
await wrapped(change, {
4342
params: {
4443
uid: userRecord.uid
4544
}
46-
}).then(() => {
47-
return admin
48-
.auth()
49-
.getUser(userRecord.uid)
50-
.then(snap => {
51-
chai.assert.isTrue(snap.customClaims!.isAdmin);
52-
});
5345
});
46+
return admin
47+
.auth()
48+
.getUser(userRecord.uid)
49+
.then(snap => {
50+
chai.assert.isTrue(snap.customClaims!.isAdmin);
51+
});
5452
});
5553
});

functions/test/https/createUser.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import { admin, test } from '../util/admin';
1+
import { admin, test } from '../util/config';
22
import { https } from 'firebase-functions';
33
import * as chai from 'chai';
4+
import * as chaiAsPromised from 'chai-as-promised';
45
import * as createUser from '../../src/https/createUser.function';
56
import 'mocha';
67

8+
chai.use(chaiAsPromised);
9+
710
describe('createUser', () => {
811
let userRecord: any;
912

File renamed without changes.

functions/tsconfig.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
"outDir": "lib",
77
"sourceMap": true,
88
"strict": true,
9-
"target": "es2017"
9+
"target": "es2017",
10+
"resolveJsonModule": true
1011
},
1112
"compileOnSave": true,
12-
"include": [
13-
"src"
14-
]
13+
"include": ["src"]
1514
}

0 commit comments

Comments
 (0)