|
1 | 1 | /* eslint-disable no-console */
|
2 | 2 | const { getE2eTestProject, getE2eEmulatorHost } = require('../../app/e2e/helpers');
|
3 | 3 | const http = require('http');
|
| 4 | +const fetch = require('node-fetch'); |
4 | 5 |
|
5 | 6 | // Call HTTP REST API URL and return JSON response parsed into object
|
6 | 7 | const callRestApi = async function callRestAPI(url, rawResult = false) {
|
@@ -34,53 +35,48 @@ function getRandomPhoneNumber() {
|
34 | 35 | exports.getRandomPhoneNumber = getRandomPhoneNumber;
|
35 | 36 |
|
36 | 37 | exports.clearAllUsers = async function clearAllUsers() {
|
37 |
| - // console.log('auth::helpers::clearAllUsers'); |
| 38 | + // console.error('auth::helpers::clearAllUsers'); |
38 | 39 | 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' }, |
44 | 50 | },
|
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)); |
55 | 55 | } catch (e) {
|
56 | 56 | console.error('Unable to wipe auth:', e);
|
57 | 57 | throw e;
|
58 | 58 | }
|
59 | 59 | };
|
60 | 60 |
|
61 | 61 | 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); |
64 | 63 | 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' }, |
72 | 75 | },
|
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)); |
84 | 80 | } catch (e) {
|
85 | 81 | console.error('Unable to update user:', e);
|
86 | 82 | throw e;
|
|
0 commit comments