Skip to content

Commit 12eb6c8

Browse files
authored
refactor: replace hardcoded error codes with references (#7546)
1 parent b5fc0d5 commit 12eb6c8

13 files changed

+85
-52
lines changed

spec/AuthenticationAdapters.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,7 @@ describe('microsoft graph auth adapter', () => {
17501750
access_token: 'very.long.bad.token',
17511751
};
17521752
microsoft.validateAuthData(authData).then(done.fail, err => {
1753-
expect(err.code).toBe(101);
1753+
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
17541754
expect(err.message).toBe('Microsoft Graph auth is invalid for this user.');
17551755
done();
17561756
});

spec/CloudCode.spec.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe('Cloud Code', () => {
7575

7676
it('is cleared cleared after the previous test', done => {
7777
Parse.Cloud.run('hello', {}).catch(error => {
78-
expect(error.code).toEqual(141);
78+
expect(error.code).toEqual(Parse.Error.SCRIPT_FAILED);
7979
done();
8080
});
8181
});
@@ -109,7 +109,7 @@ describe('Cloud Code', () => {
109109
Parse.Cloud.run('cloudCodeWithError').then(
110110
() => done.fail('should not succeed'),
111111
e => {
112-
expect(e).toEqual(new Parse.Error(141, 'foo is not defined'));
112+
expect(e).toEqual(new Parse.Error(Parse.Error.SCRIPT_FAILED, 'foo is not defined'));
113113
done();
114114
}
115115
);
@@ -123,7 +123,7 @@ describe('Cloud Code', () => {
123123
Parse.Cloud.run('cloudCodeWithError').then(
124124
() => done.fail('should not succeed'),
125125
e => {
126-
expect(e.code).toEqual(141);
126+
expect(e.code).toEqual(Parse.Error.SCRIPT_FAILED);
127127
expect(e.message).toEqual('Script failed.');
128128
done();
129129
}
@@ -142,7 +142,7 @@ describe('Cloud Code', () => {
142142
const query = new Parse.Query('beforeFind');
143143
await query.first();
144144
} catch (e) {
145-
expect(e.code).toBe(141);
145+
expect(e.code).toBe(Parse.Error.SCRIPT_FAILED);
146146
expect(e.message).toBe('throw beforeFind');
147147
done();
148148
}
@@ -467,7 +467,7 @@ describe('Cloud Code', () => {
467467
});
468468
} catch (e) {
469469
catched = true;
470-
expect(e.code).toBe(101);
470+
expect(e.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
471471
}
472472
expect(catched).toBe(true);
473473
expect(called).toBe(7);
@@ -479,7 +479,7 @@ describe('Cloud Code', () => {
479479
});
480480
} catch (e) {
481481
catched = true;
482-
expect(e.code).toBe(101);
482+
expect(e.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
483483
}
484484
expect(catched).toBe(true);
485485
expect(called).toBe(7);
@@ -491,7 +491,7 @@ describe('Cloud Code', () => {
491491
});
492492
} catch (e) {
493493
catched = true;
494-
expect(e.code).toBe(101);
494+
expect(e.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
495495
}
496496
expect(catched).toBe(true);
497497
expect(called).toBe(7);
@@ -1761,7 +1761,7 @@ describe('Cloud Code', () => {
17611761

17621762
it('should set the failure message on the job error', async () => {
17631763
Parse.Cloud.job('myJobError', () => {
1764-
throw new Parse.Error(101, 'Something went wrong');
1764+
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Something went wrong');
17651765
});
17661766
const job = await Parse.Cloud.startJob('myJobError');
17671767
let jobStatus, status;
@@ -2038,7 +2038,7 @@ describe('beforeFind hooks', () => {
20382038
done();
20392039
},
20402040
err => {
2041-
expect(err.code).toBe(141);
2041+
expect(err.code).toBe(Parse.Error.SCRIPT_FAILED);
20422042
expect(err.message).toEqual('Do not run that query');
20432043
done();
20442044
}

spec/CloudCodeLogger.spec.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ describe('Cloud Code Logger', () => {
161161
expect(log[0]).toEqual('error');
162162
const error = log[2].error;
163163
expect(error instanceof Parse.Error).toBeTruthy();
164-
expect(error.code).toBe(141);
164+
expect(error.code).toBe(Parse.Error.SCRIPT_FAILED);
165165
expect(error.message).toBe('uh oh!');
166166
done();
167167
});
@@ -199,7 +199,9 @@ describe('Cloud Code Logger', () => {
199199
expect(log[1]).toMatch(
200200
/Failed running cloud function aFunction for user [^ ]* with:\n {2}Input: {"foo":"bar"}\n {2}Error:/
201201
);
202-
const errorString = JSON.stringify(new Parse.Error(141, 'it failed!'));
202+
const errorString = JSON.stringify(
203+
new Parse.Error(Parse.Error.SCRIPT_FAILED, 'it failed!')
204+
);
203205
expect(log[1].indexOf(errorString)).toBeGreaterThan(0);
204206
done();
205207
})

spec/ParseAPI.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ describe('miscellaneous', function () {
10151015
done();
10161016
},
10171017
e => {
1018-
expect(e.code).toEqual(141);
1018+
expect(e.code).toEqual(Parse.Error.SCRIPT_FAILED);
10191019
expect(e.message).toEqual('noway');
10201020
done();
10211021
}

spec/ParseHooks.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ describe('Hooks', () => {
464464
expect(err).not.toBe(undefined);
465465
expect(err).not.toBe(null);
466466
if (err) {
467-
expect(err.code).toBe(141);
467+
expect(err.code).toBe(Parse.Error.SCRIPT_FAILED);
468468
expect(err.message.code).toEqual(1337);
469469
expect(err.message.error).toEqual('hacking that one!');
470470
}
@@ -536,7 +536,7 @@ describe('Hooks', () => {
536536
expect(err).not.toBe(undefined);
537537
expect(err).not.toBe(null);
538538
if (err) {
539-
expect(err.code).toBe(141);
539+
expect(err.code).toBe(Parse.Error.SCRIPT_FAILED);
540540
expect(err.message).toEqual('incorrect key provided');
541541
}
542542
done();

spec/ParseRole.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ describe('Parse Role testing', () => {
428428
},
429429
e => {
430430
if (e) {
431-
expect(e.code).toEqual(101);
431+
expect(e.code).toEqual(Parse.Error.OBJECT_NOT_FOUND);
432432
} else {
433433
fail('should return an error');
434434
}

spec/ParseUser.spec.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ describe('Parse.User testing', () => {
7272
})
7373
.catch(err => {
7474
expect(err.status).toBe(404);
75-
expect(err.text).toMatch('{"code":101,"error":"Invalid username/password."}');
75+
expect(err.text).toMatch(
76+
`{"code":${Parse.Error.OBJECT_NOT_FOUND},"error":"Invalid username/password."}`
77+
);
7678
done();
7779
});
7880
});
@@ -99,7 +101,9 @@ describe('Parse.User testing', () => {
99101
})
100102
.catch(err => {
101103
expect(err.status).toBe(404);
102-
expect(err.text).toMatch('{"code":101,"error":"Invalid username/password."}');
104+
expect(err.text).toMatch(
105+
`{"code":${Parse.Error.OBJECT_NOT_FOUND},"error":"Invalid username/password."}`
106+
);
103107
done();
104108
});
105109
});

spec/PointerPermissions.spec.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('Pointer Permissions', () => {
9999
},
100100
err => {
101101
// User 1 should not be able to update obj2
102-
expect(err.code).toBe(101);
102+
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
103103
return Promise.resolve();
104104
}
105105
)
@@ -203,7 +203,7 @@ describe('Pointer Permissions', () => {
203203
fail('User 2 should not get the obj1 object');
204204
},
205205
err => {
206-
expect(err.code).toBe(101);
206+
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
207207
expect(err.message).toBe('Object not found.');
208208
return Promise.resolve();
209209
}
@@ -530,7 +530,7 @@ describe('Pointer Permissions', () => {
530530
done();
531531
},
532532
err => {
533-
expect(err.code).toBe(101);
533+
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
534534
done();
535535
}
536536
);
@@ -583,7 +583,7 @@ describe('Pointer Permissions', () => {
583583
done();
584584
},
585585
err => {
586-
expect(err.code).toBe(101);
586+
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
587587
done();
588588
}
589589
);
@@ -695,7 +695,7 @@ describe('Pointer Permissions', () => {
695695
done();
696696
},
697697
err => {
698-
expect(err.code).toBe(101);
698+
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
699699
done();
700700
}
701701
);
@@ -819,7 +819,7 @@ describe('Pointer Permissions', () => {
819819
done();
820820
},
821821
err => {
822-
expect(err.code).toBe(101);
822+
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
823823
done();
824824
}
825825
);
@@ -848,7 +848,7 @@ describe('Pointer Permissions', () => {
848848
.then(
849849
() => {},
850850
err => {
851-
expect(err.code).toBe(101);
851+
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
852852
return Promise.resolve();
853853
}
854854
)
@@ -891,7 +891,7 @@ describe('Pointer Permissions', () => {
891891
.then(
892892
() => {},
893893
err => {
894-
expect(err.code).toBe(101);
894+
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
895895
return Promise.resolve();
896896
}
897897
)
@@ -934,7 +934,7 @@ describe('Pointer Permissions', () => {
934934
.then(
935935
() => {},
936936
err => {
937-
expect(err.code).toBe(101);
937+
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
938938
return Promise.resolve();
939939
}
940940
)
@@ -977,7 +977,7 @@ describe('Pointer Permissions', () => {
977977
fail();
978978
},
979979
err => {
980-
expect(err.code).toBe(101);
980+
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
981981
return Promise.resolve();
982982
}
983983
)
@@ -1111,7 +1111,7 @@ describe('Pointer Permissions', () => {
11111111
done.fail('User should not be able to update obj2');
11121112
} catch (err) {
11131113
// User 1 should not be able to update obj2
1114-
expect(err.code).toBe(101);
1114+
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
11151115
}
11161116

11171117
obj.set('hello', 'world');
@@ -1186,7 +1186,7 @@ describe('Pointer Permissions', () => {
11861186
await q.get(obj.id);
11871187
done.fail('User 3 should not get the obj1 object');
11881188
} catch (err) {
1189-
expect(err.code).toBe(101);
1189+
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
11901190
expect(err.message).toBe('Object not found.');
11911191
}
11921192

@@ -1541,7 +1541,7 @@ describe('Pointer Permissions', () => {
15411541
await obj.save({ key: 'value' });
15421542
done.fail('Should not succeed saving');
15431543
} catch (err) {
1544-
expect(err.code).toBe(101);
1544+
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
15451545
done();
15461546
}
15471547
});
@@ -1590,7 +1590,7 @@ describe('Pointer Permissions', () => {
15901590
await obj.save({ key: 'value' });
15911591
done.fail('Should not succeed saving');
15921592
} catch (err) {
1593-
expect(err.code).toBe(101);
1593+
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
15941594
}
15951595
}
15961596
done();
@@ -1692,7 +1692,7 @@ describe('Pointer Permissions', () => {
16921692
await obj.fetch();
16931693
done.fail('Should not succeed fetching');
16941694
} catch (err) {
1695-
expect(err.code).toBe(101);
1695+
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
16961696
done();
16971697
}
16981698
done();
@@ -1811,7 +1811,7 @@ describe('Pointer Permissions', () => {
18111811
await obj.fetch();
18121812
done.fail('Should not succeed fetching');
18131813
} catch (err) {
1814-
expect(err.code).toBe(101);
1814+
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
18151815
}
18161816
}
18171817
done();
@@ -1863,7 +1863,7 @@ describe('Pointer Permissions', () => {
18631863
await q.get(object.id);
18641864
done.fail();
18651865
} catch (err) {
1866-
expect(err.code).toBe(101);
1866+
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
18671867
}
18681868

18691869
try {
@@ -1894,7 +1894,7 @@ describe('Pointer Permissions', () => {
18941894
await object.save({ hello: 'bar' });
18951895
done.fail();
18961896
} catch (err) {
1897-
expect(err.code).toBe(101);
1897+
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
18981898
}
18991899

19001900
try {
@@ -1925,7 +1925,7 @@ describe('Pointer Permissions', () => {
19251925
await object.destroy();
19261926
done.fail();
19271927
} catch (err) {
1928-
expect(err.code).toBe(101);
1928+
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
19291929
}
19301930
try {
19311931
await object.destroy({ useMasterKey: true });

spec/PushWorker.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ describe('PushWorker', () => {
249249
// should not be deleted
250250
transmitted: false,
251251
device: {
252-
deviceToken: 101,
252+
deviceToken: Parse.Error.OBJECT_NOT_FOUND,
253253
deviceType: 'ios',
254254
},
255255
response: { error: 'invalid error...' },

spec/RegexVulnerabilities.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ describe('Regex Vulnerabilities', function () {
147147
await Parse.User.logIn('[email protected]', 'newpassword');
148148
fail('should not work');
149149
} catch (e) {
150-
expect(e.code).toEqual(101);
150+
expect(e.code).toEqual(Parse.Error.OBJECT_NOT_FOUND);
151151
expect(e.message).toEqual('Invalid username/password.');
152152
}
153153
});

0 commit comments

Comments
 (0)