refactor: replace hardcoded error codes with references (#7546)
This commit is contained in:
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
@@ -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();
|
||||
}
|
||||
);
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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;
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
@@ -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();
|
||||
})
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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!');
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
)
|
||||
@@ -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();
|
||||
}
|
||||
@@ -530,7 +530,7 @@ describe('Pointer Permissions', () => {
|
||||
done();
|
||||
},
|
||||
err => {
|
||||
expect(err.code).toBe(101);
|
||||
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
|
||||
done();
|
||||
}
|
||||
);
|
||||
@@ -583,7 +583,7 @@ describe('Pointer Permissions', () => {
|
||||
done();
|
||||
},
|
||||
err => {
|
||||
expect(err.code).toBe(101);
|
||||
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
|
||||
done();
|
||||
}
|
||||
);
|
||||
@@ -695,7 +695,7 @@ describe('Pointer Permissions', () => {
|
||||
done();
|
||||
},
|
||||
err => {
|
||||
expect(err.code).toBe(101);
|
||||
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
|
||||
done();
|
||||
}
|
||||
);
|
||||
@@ -819,7 +819,7 @@ describe('Pointer Permissions', () => {
|
||||
done();
|
||||
},
|
||||
err => {
|
||||
expect(err.code).toBe(101);
|
||||
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
|
||||
done();
|
||||
}
|
||||
);
|
||||
@@ -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();
|
||||
}
|
||||
)
|
||||
@@ -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();
|
||||
}
|
||||
)
|
||||
@@ -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();
|
||||
}
|
||||
)
|
||||
@@ -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();
|
||||
}
|
||||
)
|
||||
@@ -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');
|
||||
@@ -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.');
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
@@ -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();
|
||||
@@ -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();
|
||||
@@ -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();
|
||||
@@ -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 {
|
||||
@@ -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 {
|
||||
@@ -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 });
|
||||
|
||||
@@ -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...' },
|
||||
|
||||
@@ -147,7 +147,7 @@ describe('Regex Vulnerabilities', function () {
|
||||
await Parse.User.logIn('someemail@somedomain.com', '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.');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -79,7 +79,9 @@ describe('Verify User Password', () => {
|
||||
})
|
||||
.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();
|
||||
});
|
||||
});
|
||||
@@ -221,7 +223,9 @@ describe('Verify User Password', () => {
|
||||
})
|
||||
.then(res => {
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.text).toMatch('{"code":101,"error":"Invalid username/password."}');
|
||||
expect(res.text).toMatch(
|
||||
`{"code":${Parse.Error.OBJECT_NOT_FOUND},"error":"Invalid username/password."}`
|
||||
);
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
@@ -242,7 +246,9 @@ describe('Verify User Password', () => {
|
||||
})
|
||||
.then(res => {
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.text).toMatch('{"code":101,"error":"Invalid username/password."}');
|
||||
expect(res.text).toMatch(
|
||||
`{"code":${Parse.Error.OBJECT_NOT_FOUND},"error":"Invalid username/password."}`
|
||||
);
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
@@ -263,7 +269,9 @@ describe('Verify User Password', () => {
|
||||
})
|
||||
.then(res => {
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.text).toMatch('{"code":101,"error":"Invalid username/password."}');
|
||||
expect(res.text).toMatch(
|
||||
`{"code":${Parse.Error.OBJECT_NOT_FOUND},"error":"Invalid username/password."}`
|
||||
);
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
@@ -284,7 +292,9 @@ describe('Verify User Password', () => {
|
||||
})
|
||||
.then(res => {
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.text).toMatch('{"code":101,"error":"Invalid username/password."}');
|
||||
expect(res.text).toMatch(
|
||||
`{"code":${Parse.Error.OBJECT_NOT_FOUND},"error":"Invalid username/password."}`
|
||||
);
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
@@ -305,7 +315,9 @@ describe('Verify User Password', () => {
|
||||
})
|
||||
.then(res => {
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.text).toMatch('{"code":101,"error":"Invalid username/password."}');
|
||||
expect(res.text).toMatch(
|
||||
`{"code":${Parse.Error.OBJECT_NOT_FOUND},"error":"Invalid username/password."}`
|
||||
);
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
@@ -317,7 +329,9 @@ describe('Verify User Password', () => {
|
||||
verifyPassword('mytestuser', 'mypass')
|
||||
.then(res => {
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.text).toMatch('{"code":101,"error":"Invalid username/password."}');
|
||||
expect(res.text).toMatch(
|
||||
`{"code":${Parse.Error.OBJECT_NOT_FOUND},"error":"Invalid username/password."}`
|
||||
);
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
@@ -329,7 +343,9 @@ describe('Verify User Password', () => {
|
||||
verifyPassword('my@user.com', 'mypass', true)
|
||||
.then(res => {
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.text).toMatch('{"code":101,"error":"Invalid username/password."}');
|
||||
expect(res.text).toMatch(
|
||||
`{"code":${Parse.Error.OBJECT_NOT_FOUND},"error":"Invalid username/password."}`
|
||||
);
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
|
||||
Reference in New Issue
Block a user