Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dblythy committed Dec 24, 2024
1 parent f8adefc commit f8c5e28
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/PromiseRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ function makeExpressHandler(appId, promiseHandler) {

res.json(result.response);
} catch (error) {
log.error(`Error handling request: ${error.message}`, { error });
next(error);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/Routers/FunctionsRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class FunctionsRouter extends PromiseRouter {

if (req.config.logLevels.cloudFunctionSuccess !== 'silent') {
const cleanInput = logger.truncateLogMessage(JSON.stringify(params));
const cleanResult = logger.truncateLogMessage(JSON.stringify(result.response?.result));
const cleanResult = logger.truncateLogMessage(JSON.stringify(result));
logger[req.config.logLevels.cloudFunctionSuccess](
`Ran cloud function ${functionName} for user ${userString} with:\n Input: ${cleanInput}\n Result: ${cleanResult}`,
{
Expand Down
50 changes: 37 additions & 13 deletions src/Triggers/Trigger.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getTrigger, Types } from "./TriggerStore";
import { maybeRunValidator } from "./Validator";
import { logTriggerAfterHook } from "./Logger";
import { logTriggerAfterHook, logTriggerSuccessBeforeHook, logTriggerErrorBeforeHook } from "./Logger";
import { toJSONwithObjects, resolveError } from "./Utils";

export function getRequestObject(
Expand Down Expand Up @@ -57,7 +57,8 @@ export async function maybeRunTrigger(
parseObject,
originalParseObject,
config,
context
context,
responseObject
) {
try {
if (!parseObject) {
Expand All @@ -84,7 +85,7 @@ export async function maybeRunTrigger(
return;
}

const response = await trigger(request);
const response = await trigger(request, responseObject);

if (triggerType === Types.afterSave || triggerType === Types.afterDelete) {
logTriggerAfterHook(
Expand All @@ -96,12 +97,35 @@ export async function maybeRunTrigger(
);
}

return processTriggerResponse(request, response);
const object = processTriggerResponse(request, response);
logTriggerSuccessBeforeHook(
triggerType,
parseObject.className,
parseObject.toJSON(),
object,
auth,
triggerType.startsWith('after')
? config.logLevels.triggerAfter
: config.logLevels.triggerBeforeSuccess
);

return object;
} catch (e) {
throw resolveError(e, {

const error = resolveError(e, {
code: Parse.Error.SCRIPT_FAILED,
message: 'Script failed.',
});

logTriggerErrorBeforeHook(
triggerType,
parseObject.className,
parseObject.toJSON(),
auth,
error,
config.logLevels.triggerBeforeError
);
throw error;
}
}

Expand All @@ -110,14 +134,14 @@ function processTriggerResponse(request, response) {
return (response || request.objects).map(toJSONwithObjects);
}

if (
response &&
typeof response === 'object' &&
request.triggerName === Types.beforeSave &&
!request.object.equals(response)
) {
return response;
}
// if (
// response &&
// typeof response === 'object' &&
// request.triggerName === Types.beforeSave &&
// !request.object.equals(response)
// ) {
// return response;
// }

if (response && typeof response === 'object' && request.triggerName === Types.afterSave) {
return response;
Expand Down

0 comments on commit f8c5e28

Please sign in to comment.