Skip to content

Commit b0908e8

Browse files
committed
test(auth): convert users delete / disable helpers to node-fetch style
something about the http module and the previous style of posting to the emulator wasn't working, in the same way remote-config realtime template update cloud function wasn't working even though it looked perfect node-fetch works great though, so convert the two helpers to that this may be related to a node v18 switch pending / in testing locally where http module works for v16 but not v18, but node-fetch works for both
1 parent b8531cd commit b0908e8

File tree

1 file changed

+32
-36
lines changed

1 file changed

+32
-36
lines changed

packages/auth/e2e/helpers.js

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable no-console */
22
const { getE2eTestProject, getE2eEmulatorHost } = require('../../app/e2e/helpers');
33
const http = require('http');
4+
const fetch = require('node-fetch');
45

56
// Call HTTP REST API URL and return JSON response parsed into object
67
const callRestApi = async function callRestAPI(url, rawResult = false) {
@@ -34,53 +35,48 @@ function getRandomPhoneNumber() {
3435
exports.getRandomPhoneNumber = getRandomPhoneNumber;
3536

3637
exports.clearAllUsers = async function clearAllUsers() {
37-
// console.log('auth::helpers::clearAllUsers');
38+
// console.error('auth::helpers::clearAllUsers');
3839
try {
39-
const deleteOptions = {
40-
method: 'DELETE',
41-
headers: {
42-
// Undocumented, but necessary - from Emulator UI network requests
43-
Authorization: 'Bearer owner',
40+
const response = await fetch(
41+
'http://' +
42+
getE2eEmulatorHost() +
43+
':9099' +
44+
'/emulator/v1/projects/' +
45+
getE2eTestProject() +
46+
'/accounts',
47+
{
48+
method: 'delete',
49+
headers: { Authorization: 'Bearer owner' },
4450
},
45-
port: 9099,
46-
host: getE2eEmulatorHost(),
47-
path: '/emulator/v1/projects/' + getE2eTestProject() + '/accounts',
48-
};
49-
// console.log('request: ' + JSON.stringify(deleteOptions));
50-
await new Promise((resolve, reject) => {
51-
const req = http.request(deleteOptions);
52-
req.on('error', error => reject(error));
53-
req.end(resolve());
54-
});
51+
);
52+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
53+
const result = await response.json();
54+
// console.error('received: ' + JSON.stringify(result));
5555
} catch (e) {
5656
console.error('Unable to wipe auth:', e);
5757
throw e;
5858
}
5959
};
6060

6161
exports.disableUser = async function disableUser(userId) {
62-
// console.log('auth::helpers::disableUser on userId: ' + userId);
63-
const reqBody = JSON.stringify({ disableUser: true, localId: userId });
62+
// console.error('auth::helpers::disableUser on userId: ' + userId);
6463
try {
65-
const postOptions = {
66-
method: 'POST',
67-
headers: {
68-
// Undocumented, but necessary - from Emulator UI network requests
69-
Authorization: 'Bearer owner',
70-
'Content-Type': 'application/json',
71-
'Content-Length': reqBody.length,
64+
const response = await fetch(
65+
'http://' +
66+
getE2eEmulatorHost() +
67+
':9099' +
68+
'/identitytoolkit.googleapis.com/v1/projects/' +
69+
getE2eTestProject() +
70+
'/accounts:update',
71+
{
72+
method: 'post',
73+
body: JSON.stringify({ disableUser: true, localId: userId }),
74+
headers: { Authorization: 'Bearer owner', 'Content-Type': 'application/json' },
7275
},
73-
port: 9099,
74-
host: getE2eEmulatorHost(),
75-
path: '/identitytoolkit.googleapis.com/v1/accounts:update',
76-
};
77-
// console.log('request: ' + JSON.stringify(postOptions));
78-
await new Promise((resolve, reject) => {
79-
const req = http.request(postOptions);
80-
req.on('error', error => reject(error));
81-
req.write(reqBody);
82-
req.end(resolve());
83-
});
76+
);
77+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
78+
const result = await response.json();
79+
// console.error('received: ' + JSON.stringify(result));
8480
} catch (e) {
8581
console.error('Unable to update user:', e);
8682
throw e;

0 commit comments

Comments
 (0)