Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace hardcoded error codes with references #7546

Merged
merged 10 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/AuthenticationAdapters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,7 @@ describe('microsoft graph auth adapter', () => {
access_token: 'very.long.bad.token',
};
microsoft.validateAuthData(authData).then(done.fail, err => {
expect(err.code).toBe(101);
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
expect(err.message).toBe('Microsoft Graph auth is invalid for this user.');
done();
});
Expand Down
18 changes: 9 additions & 9 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('Cloud Code', () => {

it('is cleared cleared after the previous test', done => {
Parse.Cloud.run('hello', {}).catch(error => {
expect(error.code).toEqual(141);
expect(error.code).toEqual(Parse.Error.SCRIPT_FAILED);
done();
});
});
Expand Down Expand Up @@ -109,7 +109,7 @@ describe('Cloud Code', () => {
Parse.Cloud.run('cloudCodeWithError').then(
() => done.fail('should not succeed'),
e => {
expect(e).toEqual(new Parse.Error(141, 'foo is not defined'));
expect(e).toEqual(new Parse.Error(Parse.Error.SCRIPT_FAILED, 'foo is not defined'));
done();
}
);
Expand All @@ -123,7 +123,7 @@ describe('Cloud Code', () => {
Parse.Cloud.run('cloudCodeWithError').then(
() => done.fail('should not succeed'),
e => {
expect(e.code).toEqual(141);
expect(e.code).toEqual(Parse.Error.SCRIPT_FAILED);
expect(e.message).toEqual('Script failed.');
done();
}
Expand All @@ -142,7 +142,7 @@ describe('Cloud Code', () => {
const query = new Parse.Query('beforeFind');
await query.first();
} catch (e) {
expect(e.code).toBe(141);
expect(e.code).toBe(Parse.Error.SCRIPT_FAILED);
expect(e.message).toBe('throw beforeFind');
done();
}
Expand Down Expand Up @@ -467,7 +467,7 @@ describe('Cloud Code', () => {
});
} catch (e) {
catched = true;
expect(e.code).toBe(101);
expect(e.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
}
expect(catched).toBe(true);
expect(called).toBe(7);
Expand All @@ -479,7 +479,7 @@ describe('Cloud Code', () => {
});
} catch (e) {
catched = true;
expect(e.code).toBe(101);
expect(e.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
}
expect(catched).toBe(true);
expect(called).toBe(7);
Expand All @@ -491,7 +491,7 @@ describe('Cloud Code', () => {
});
} catch (e) {
catched = true;
expect(e.code).toBe(101);
expect(e.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
}
expect(catched).toBe(true);
expect(called).toBe(7);
Expand Down Expand Up @@ -1761,7 +1761,7 @@ describe('Cloud Code', () => {

it('should set the failure message on the job error', async () => {
Parse.Cloud.job('myJobError', () => {
throw new Parse.Error(101, 'Something went wrong');
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Something went wrong');
});
const job = await Parse.Cloud.startJob('myJobError');
let jobStatus, status;
Expand Down Expand Up @@ -2038,7 +2038,7 @@ describe('beforeFind hooks', () => {
done();
},
err => {
expect(err.code).toBe(141);
expect(err.code).toBe(Parse.Error.SCRIPT_FAILED);
expect(err.message).toEqual('Do not run that query');
done();
}
Expand Down
6 changes: 4 additions & 2 deletions spec/CloudCodeLogger.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ describe('Cloud Code Logger', () => {
expect(log[0]).toEqual('error');
const error = log[2].error;
expect(error instanceof Parse.Error).toBeTruthy();
expect(error.code).toBe(141);
expect(error.code).toBe(Parse.Error.SCRIPT_FAILED);
expect(error.message).toBe('uh oh!');
done();
});
Expand Down Expand Up @@ -199,7 +199,9 @@ describe('Cloud Code Logger', () => {
expect(log[1]).toMatch(
/Failed running cloud function aFunction for user [^ ]* with:\n {2}Input: {"foo":"bar"}\n {2}Error:/
);
const errorString = JSON.stringify(new Parse.Error(141, 'it failed!'));
const errorString = JSON.stringify(
new Parse.Error(Parse.Error.SCRIPT_FAILED, 'it failed!')
);
expect(log[1].indexOf(errorString)).toBeGreaterThan(0);
done();
})
Expand Down
2 changes: 1 addition & 1 deletion spec/ParseAPI.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ describe('miscellaneous', function () {
done();
},
e => {
expect(e.code).toEqual(141);
expect(e.code).toEqual(Parse.Error.SCRIPT_FAILED);
expect(e.message).toEqual('noway');
done();
}
Expand Down
4 changes: 2 additions & 2 deletions spec/ParseHooks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ describe('Hooks', () => {
expect(err).not.toBe(undefined);
expect(err).not.toBe(null);
if (err) {
expect(err.code).toBe(141);
expect(err.code).toBe(Parse.Error.SCRIPT_FAILED);
expect(err.message.code).toEqual(1337);
expect(err.message.error).toEqual('hacking that one!');
}
Expand Down Expand Up @@ -536,7 +536,7 @@ describe('Hooks', () => {
expect(err).not.toBe(undefined);
expect(err).not.toBe(null);
if (err) {
expect(err.code).toBe(141);
expect(err.code).toBe(Parse.Error.SCRIPT_FAILED);
expect(err.message).toEqual('incorrect key provided');
}
done();
Expand Down
2 changes: 1 addition & 1 deletion spec/ParseRole.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ describe('Parse Role testing', () => {
},
e => {
if (e) {
expect(e.code).toEqual(101);
expect(e.code).toEqual(Parse.Error.OBJECT_NOT_FOUND);
} else {
fail('should return an error');
}
Expand Down
8 changes: 6 additions & 2 deletions spec/ParseUser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ describe('Parse.User testing', () => {
})
.catch(err => {
expect(err.status).toBe(404);
expect(err.text).toMatch('{"code":101,"error":"Invalid username/password."}');
expect(err.text).toMatch(
`{"code":${Parse.Error.OBJECT_NOT_FOUND},"error":"Invalid username/password."}`
);
done();
});
});
Expand All @@ -99,7 +101,9 @@ describe('Parse.User testing', () => {
})
.catch(err => {
expect(err.status).toBe(404);
expect(err.text).toMatch('{"code":101,"error":"Invalid username/password."}');
expect(err.text).toMatch(
`{"code":${Parse.Error.OBJECT_NOT_FOUND},"error":"Invalid username/password."}`
);
done();
});
});
Expand Down
38 changes: 19 additions & 19 deletions spec/PointerPermissions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('Pointer Permissions', () => {
},
err => {
// User 1 should not be able to update obj2
expect(err.code).toBe(101);
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
return Promise.resolve();
}
)
Expand Down Expand Up @@ -203,7 +203,7 @@ describe('Pointer Permissions', () => {
fail('User 2 should not get the obj1 object');
},
err => {
expect(err.code).toBe(101);
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
expect(err.message).toBe('Object not found.');
return Promise.resolve();
}
Expand Down Expand Up @@ -530,7 +530,7 @@ describe('Pointer Permissions', () => {
done();
},
err => {
expect(err.code).toBe(101);
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
done();
}
);
Expand Down Expand Up @@ -583,7 +583,7 @@ describe('Pointer Permissions', () => {
done();
},
err => {
expect(err.code).toBe(101);
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
done();
}
);
Expand Down Expand Up @@ -695,7 +695,7 @@ describe('Pointer Permissions', () => {
done();
},
err => {
expect(err.code).toBe(101);
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
done();
}
);
Expand Down Expand Up @@ -819,7 +819,7 @@ describe('Pointer Permissions', () => {
done();
},
err => {
expect(err.code).toBe(101);
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
done();
}
);
Expand Down Expand Up @@ -848,7 +848,7 @@ describe('Pointer Permissions', () => {
.then(
() => {},
err => {
expect(err.code).toBe(101);
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
return Promise.resolve();
}
)
Expand Down Expand Up @@ -891,7 +891,7 @@ describe('Pointer Permissions', () => {
.then(
() => {},
err => {
expect(err.code).toBe(101);
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
return Promise.resolve();
}
)
Expand Down Expand Up @@ -934,7 +934,7 @@ describe('Pointer Permissions', () => {
.then(
() => {},
err => {
expect(err.code).toBe(101);
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
return Promise.resolve();
}
)
Expand Down Expand Up @@ -977,7 +977,7 @@ describe('Pointer Permissions', () => {
fail();
},
err => {
expect(err.code).toBe(101);
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
return Promise.resolve();
}
)
Expand Down Expand Up @@ -1111,7 +1111,7 @@ describe('Pointer Permissions', () => {
done.fail('User should not be able to update obj2');
} catch (err) {
// User 1 should not be able to update obj2
expect(err.code).toBe(101);
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
}

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

Expand Down Expand Up @@ -1541,7 +1541,7 @@ describe('Pointer Permissions', () => {
await obj.save({ key: 'value' });
done.fail('Should not succeed saving');
} catch (err) {
expect(err.code).toBe(101);
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
done();
}
});
Expand Down Expand Up @@ -1590,7 +1590,7 @@ describe('Pointer Permissions', () => {
await obj.save({ key: 'value' });
done.fail('Should not succeed saving');
} catch (err) {
expect(err.code).toBe(101);
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
}
}
done();
Expand Down Expand Up @@ -1692,7 +1692,7 @@ describe('Pointer Permissions', () => {
await obj.fetch();
done.fail('Should not succeed fetching');
} catch (err) {
expect(err.code).toBe(101);
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
done();
}
done();
Expand Down Expand Up @@ -1811,7 +1811,7 @@ describe('Pointer Permissions', () => {
await obj.fetch();
done.fail('Should not succeed fetching');
} catch (err) {
expect(err.code).toBe(101);
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
}
}
done();
Expand Down Expand Up @@ -1863,7 +1863,7 @@ describe('Pointer Permissions', () => {
await q.get(object.id);
done.fail();
} catch (err) {
expect(err.code).toBe(101);
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
}

try {
Expand Down Expand Up @@ -1894,7 +1894,7 @@ describe('Pointer Permissions', () => {
await object.save({ hello: 'bar' });
done.fail();
} catch (err) {
expect(err.code).toBe(101);
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
}

try {
Expand Down Expand Up @@ -1925,7 +1925,7 @@ describe('Pointer Permissions', () => {
await object.destroy();
done.fail();
} catch (err) {
expect(err.code).toBe(101);
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
}
try {
await object.destroy({ useMasterKey: true });
Expand Down
2 changes: 1 addition & 1 deletion spec/PushWorker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ describe('PushWorker', () => {
// should not be deleted
transmitted: false,
device: {
deviceToken: 101,
deviceToken: Parse.Error.OBJECT_NOT_FOUND,
deviceType: 'ios',
},
response: { error: 'invalid error...' },
Expand Down
2 changes: 1 addition & 1 deletion spec/RegexVulnerabilities.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe('Regex Vulnerabilities', function () {
await Parse.User.logIn('[email protected]', 'newpassword');
fail('should not work');
} catch (e) {
expect(e.code).toEqual(101);
expect(e.code).toEqual(Parse.Error.OBJECT_NOT_FOUND);
expect(e.message).toEqual('Invalid username/password.');
}
});
Expand Down
Loading