Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gautamsi committed Jul 18, 2024
1 parent 164fa7f commit 6104291
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
19 changes: 14 additions & 5 deletions tests/api-tests/hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ function makeList ({
: hooks.validate === 'throws'
? makeThrower(`${__name}_${context}`)
: ({ operation, resolvedData, addValidationError }: any) => {
addValidationError(`Validate_${__name}_${context}_${operation}`)
// TODO: mixed results
addValidationError(`Validate_${__name}_${context}_${operation}`)
// TODO: mixed results
}
}

Expand Down Expand Up @@ -85,14 +85,23 @@ function makeList ({
basis: text(hooks.field ? {
db: { isNullable: true }, // drops the implicit validation hook
hooks: {
resolveInput: hooks.resolveInput ? replaceF : undefined,
resolveInput: hooks.resolveInput ? {
create: replaceF,
update: replaceF,
} : undefined,
validate: {
create: makeValidate('FVI'),
update: makeValidate('FVI'),
delete: makeValidate('FVI'),
},
beforeOperation: hooks.beforeOperation ? makeThrower(`${__name}_FBO`) : undefined,
afterOperation: hooks.afterOperation ? makeThrower(`${__name}_FAO`) : undefined
beforeOperation: hooks.beforeOperation ? {
create: makeThrower(`${__name}_FBO`),
update: makeThrower(`${__name}_FBO`),
} : undefined,
afterOperation: hooks.afterOperation ? {
create: makeThrower(`${__name}_FAO`),
update: makeThrower(`${__name}_FAO`),
} : undefined
}
} : {}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,14 @@ const runner2 = setupTestRunner({
content: text(),
},
hooks: {
afterOperation () {
afterOperationWasCalled = true
},
afterOperation: {
create () {
afterOperationWasCalled = true
},
update () {
afterOperationWasCalled = true
},
}
},
access: allowAll,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,22 @@ export const lists = {
},
hooks: {
// every time you save, add a random number
async resolveInput (args) {
return {
...args.resolvedData[args.fieldKey],
create: {
value: Math.floor(Math.random() * 100000).toString(),
},
resolveInput: {
create (args) {
return {
...args.resolvedData[args.fieldKey],
create: {
value: Math.floor(Math.random() * 100000).toString(),
},
}
},
update (args) {
return {
...args.resolvedData[args.fieldKey],
create: {
value: Math.floor(Math.random() * 100000).toString(),
},
}
}
},
},
Expand Down

0 comments on commit 6104291

Please sign in to comment.