Skip to content

Commit

Permalink
fix(condo): DOMA-10232 some errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pahaz committed Oct 8, 2024
1 parent 09307f1 commit 51d1728
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
1 change: 1 addition & 0 deletions apps/condo/domains/banking/schema/BankSyncTask.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ describe('BankSyncTask', () => {

const updatedTask2 = await BankSyncTask.getOne(adminClient, { id: task2.id })
expect(updatedTask2.status).toEqual(TASK_ERROR_STATUS)
// TODO(pahaz): refactor this code it's locale specific!
expect(updatedTask2.meta.errorMessage).toEqual(i18n(TRANSACTIONS_NOT_ADDED.messageForUser))
expect(updatedTask2.meta).toBeTruthy()
expect(updatedTask2.meta).toMatchObject({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ describe('ReplaceOrganizationEmployeeRoleService', () => {
name: 'GQLError',
path: ['result'],
message: ERRORS.ROLES_ARE_BEING_PROCESSED.message,
// TODO(pahaz): you should refactor it somehow! it's a bad example!
extensions: expect.objectContaining(omit(ERRORS.ROLES_ARE_BEING_PROCESSED, 'messageForUser')),
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('RegisterNewUserService', () => {
'type': 'PASSWORD_TOO_SIMPLE',
'code': 'BAD_USER_INPUT',
'message': 'The provided password is too simple',
'messageForUser': 'errors.PASSWORD_TOO_SIMPLE.message',
'messageForUser': 'api.user.user.PASSWORD_TOO_SIMPLE',
},
)
})
Expand Down
9 changes: 0 additions & 9 deletions packages/keystone/apolloErrorFormatter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ describe('safeFormatError hide=false', () => {
code: 'INTERNAL_ERROR',
type: 'SOME_TYPE',
'message': 'string and 1',
'messageTemplate': message1,
messageInterpolation: {
foo: 'string',
bar: 1,
Expand Down Expand Up @@ -790,7 +789,6 @@ describe('safeFormatError hide=false', () => {
'min': 8,
},
'message': 'Password length must be between 8 and 128 characters',
'messageTemplate': 'Password length must be between {min} and {max} characters',
'variable': [
'data',
'password',
Expand All @@ -812,7 +810,6 @@ describe('safeFormatError hide=false', () => {
'min': 8,
},
'message': passwordLengthErrorMessage,
'messageTemplate': 'Password length must be between {min} and {max} characters',
'variable': [
'data',
'password',
Expand All @@ -832,7 +829,6 @@ describe('safeFormatError hide=false', () => {
'min': 8,
},
'message': 'Password length must be between 8 and 128 characters',
'messageTemplate': 'Password length must be between {min} and {max} characters',
'variable': [
'data',
'password',
Expand Down Expand Up @@ -900,7 +896,6 @@ describe('safeFormatError hide=false', () => {
'min': 8,
},
'message': 'Password length must be between 8 and 128 characters',
'messageTemplate': 'Password length must be between {min} and {max} characters',
'variable': [
'data',
'password',
Expand All @@ -925,7 +920,6 @@ describe('safeFormatError hide=false', () => {
'min': 8,
},
'message': passwordLengthErrorMessage,
'messageTemplate': 'Password length must be between {min} and {max} characters',
'variable': [
'data',
'password',
Expand Down Expand Up @@ -995,7 +989,6 @@ describe('safeFormatError hide=false', () => {
'min': 8,
},
'message': 'Password length must be between 8 and 128 characters',
'messageTemplate': 'Password length must be between {min} and {max} characters',
'variable': [
'data',
'password',
Expand All @@ -1020,7 +1013,6 @@ describe('safeFormatError hide=false', () => {
'min': 8,
},
'message': passwordLengthErrorMessage,
'messageTemplate': 'Password length must be between {min} and {max} characters',
'variable': [
'data',
'password',
Expand All @@ -1040,7 +1032,6 @@ describe('safeFormatError hide=false', () => {
'max': 128,
'min': 8,
},
'messageTemplate': 'Password length must be between {min} and {max} characters',
'type': 'INVALID_PASSWORD_LENGTH',
'variable': [
'data',
Expand Down
1 change: 0 additions & 1 deletion packages/keystone/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ class GQLError extends Error {
}
}
if (!isEmpty(fields.messageInterpolation)) {
if (fields.message.includes('{')) extensions.messageTemplate = fields.message
if (fields.message === extensions.message) {
// TODO(pahaz): DOMA-10345 throw error for that cases! Waiting for apps refactoring
console.warn(
Expand Down
14 changes: 11 additions & 3 deletions packages/keystone/test.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,20 +797,29 @@ function createRegExByTemplate (template, { eol = true, sol = true } = {}) {
const expectToThrowGQLError = async (testFunc, errorFields, path = 'obj') => {
if (isEmpty(errorFields) || typeof errorFields !== 'object') throw new Error('expectToThrowGQLError(): wrong errorFields argument')
if (!errorFields.code || !errorFields.type) throw new Error('expectToThrowGQLError(): errorFields argument: no code or no type')
if (errorFields.messageForUserTemplateKey) throw new Error('expectToThrowGQLError(): you do not really need to use `messageForUserTemplateKey` key! You should pass it as `messageForUser` value! Look like a developer error!')
if (errorFields.messageForUserTemplate) throw new Error('expectToThrowGQLError(): you do not really need to use `messageForUserTemplate` key! You should pass right `messageForUser` value! Look like a developer error!')
if (errorFields.messageForUser && !errorFields.messageForUser.startsWith('api.')) {
// TODO(pahaz): DOMA-10345 strongly check it and throw error!
console.warn('expectToThrowGQLError(): developer error! `messageForUser` should starts with `api.`')
}
if (!errorFields.message) {
// TODO(pahaz): DOMA-10345 strongly check it!
console.warn('expectToThrowGQLError(): errorFields message argument is required')
// throw new Error('expectToThrowGQLError(): errorFields message argument is required')
}
const fieldsToCheck = { ...errorFields }
if (errorFields.messageInterpolation) {
if (!isEmpty(errorFields.messageInterpolation)) {
fieldsToCheck['message'] = template(errorFields.message)(errorFields.messageInterpolation)
fieldsToCheck['messageTemplate'] = errorFields.message
}
if (errorFields.messageForUser) {
const locale = conf.DEFAULT_LOCALE
const translations = getTranslations(locale)
const translatedMessage = translations[errorFields.messageForUser]
if (!translatedMessage) {
// TODO(pahaz): DOMA-10345 throw new error!
console.warn('expectToThrowGQLError! you do not have translation key', errorFields.messageForUser)
}
if (errorFields.messageInterpolation) fieldsToCheck['messageForUserTemplate'] = translatedMessage
const interpolatedMessageForUser = template(translatedMessage)(errorFields.messageInterpolation)
if (!interpolatedMessageForUser) throw new Error(`expectToThrowGQLError(): you need to set ${errorFields.messageForUser} for locale=${locale}`)
Expand All @@ -822,7 +831,6 @@ const expectToThrowGQLError = async (testFunc, errorFields, path = 'obj') => {
// it means we want to use RegExp for our tests. Check @examples
if (errorFields?.message?.includes('{')) {
fieldsToCheck['message'] = expect.stringMatching(createRegExByTemplate(errorFields.message))
fieldsToCheck['messageTemplate'] = errorFields.message
}

await catchErrorFrom(testFunc, (caught) => {
Expand Down

0 comments on commit 51d1728

Please sign in to comment.