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 fd9d103 commit da3dc3e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Triggers/QueryTrigger.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getTrigger, Types } from "./TriggerStore";
import { getRequestObject } from './Trigger';
import { getTrigger, } from "./TriggerStore";
import { getRequestObject, Types } from './Trigger';
import { resolveError, toJSONwithObjects } from "./Utils";
import { maybeRunValidator } from "./Validator";
import { logTriggerAfterHook, logTriggerSuccessBeforeHook } from "./Logger";
Expand Down
18 changes: 16 additions & 2 deletions src/Triggers/Trigger.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getTrigger, Types } from "./TriggerStore";
import { maybeRunValidator } from "./Validator";
import { logTriggerAfterHook, logTriggerErrorBeforeHook } from "./Logger";
import { toJSONwithObjects } from "./Utils";
import { toJSONwithObjects, resolveError } from "./Utils";

export function getRequestObject(
triggerType,
Expand Down Expand Up @@ -114,7 +114,10 @@ export async function maybeRunTrigger(
err,
config.logLevels.triggerBeforeError
);
throw err;
throw resolveError(err, {
code: Parse.Error.SCRIPT_FAILED,
message: 'Script failed.',
});
}
}

Expand Down Expand Up @@ -151,3 +154,14 @@ function processTriggerResponse(request, response) {

return {};
}

export async function runTrigger(trigger, name, request, auth) {
if (!trigger) {
return;
}
await maybeRunValidator(request, name, auth);
if (request.skipWithMasterKey) {
return;
}
return await trigger(request);
}
7 changes: 5 additions & 2 deletions src/triggers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { _unregisterAll, getTrigger, Types, triggerExists, addTrigger, addFunction, getFunction, getJob, runLiveQueryEventHandlers } from "./Triggers/TriggerStore";
import { maybeRunTrigger, getRequestObject } from "./Triggers/Trigger";
import { _unregisterAll, getTrigger, Types, triggerExists, addTrigger, addFunction, getFunction, getJob, runLiveQueryEventHandlers, addLiveQueryEventHandler, addJob } from "./Triggers/TriggerStore";
import { maybeRunTrigger, getRequestObject, runTrigger } from "./Triggers/Trigger";
import { getClassName, inflate, resolveError, toJSONwithObjects } from "./Triggers/Utils";
import { maybeRunQueryTrigger,maybeRunAfterFindTrigger } from "./Triggers/QueryTrigger";
import { maybeRunValidator } from "./Triggers/Validator";
Expand All @@ -10,6 +10,7 @@ export {
_unregisterAll,
getTrigger,
maybeRunTrigger,
runTrigger,
Types,
triggerExists,
getClassName,
Expand All @@ -23,6 +24,8 @@ export {
maybeRunFileTrigger,
getRequestObject,
getJob,
addJob,
addLiveQueryEventHandler,
maybeRunGlobalConfigTrigger,
maybeRunAfterFindTrigger,
toJSONwithObjects,
Expand Down

0 comments on commit da3dc3e

Please sign in to comment.