Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dblythy committed Dec 23, 2024
1 parent d9e0bf2 commit 30866c4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 40 deletions.
62 changes: 23 additions & 39 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, logTriggerErrorBeforeHook } from "./Logger";
import { logTriggerAfterHook } from "./Logger";
import { toJSONwithObjects, resolveError } from "./Utils";

export function getRequestObject(
Expand Down Expand Up @@ -57,37 +57,36 @@ export async function maybeRunTrigger(
parseObject,
originalParseObject,
config,
context,
responseObject
context
) {
if (!parseObject) {
return {};
}
try {
if (!parseObject) {
return {};
}

const trigger = getTrigger(parseObject.className, triggerType, config.applicationId);
if (!trigger) {
return;
}
const trigger = getTrigger(parseObject.className, triggerType, config.applicationId);
if (!trigger) {
return;
}

const request = getRequestObject(
triggerType,
auth,
parseObject,
originalParseObject,
config,
context
);
const request = getRequestObject(
triggerType,
auth,
parseObject,
originalParseObject,
config,
context
);

try {
await maybeRunValidator(request, `${triggerType}.${parseObject.className}`, auth);

if (request.skipWithMasterKey) {
return;
}

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

if ([Types.afterSave, Types.afterDelete, Types.afterLogin].includes(triggerType)) {
if (triggerType === Types.afterSave || triggerType === Types.afterDelete) {
logTriggerAfterHook(
triggerType,
parseObject.className,
Expand All @@ -97,24 +96,9 @@ export async function maybeRunTrigger(
);
}

const response = await Promise.resolve(promise);
const responseData = processTriggerResponse(request, response);
if (triggerType === Types.beforeSave) {
return responseData?.object ?? null;
}

return responseData;

} catch (err) {
logTriggerErrorBeforeHook(
triggerType,
parseObject.className,
parseObject.toJSON(),
auth,
err,
config.logLevels.triggerBeforeError
);
throw resolveError(err, {
return processTriggerResponse(request, response);
} catch (e) {
throw resolveError(e, {
code: Parse.Error.SCRIPT_FAILED,
message: 'Script failed.',
});
Expand Down
2 changes: 1 addition & 1 deletion src/Triggers/TriggerStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,4 @@ export function getFunctionNames(applicationId) {
};
extractFunctionNames(null, store);
return functionNames;
}
}

0 comments on commit 30866c4

Please sign in to comment.