Skip to content

Commit

Permalink
feat: added passing redirectId to testRule
Browse files Browse the repository at this point in the history
  • Loading branch information
mwargan committed Apr 25, 2024
1 parent 3874e6e commit 2ef3059
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/useRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,28 @@ const getAllRules = async (redirectId?: string) => {
* @param ruleName
* @param operator
* @param value
* @param redirectId
* @returns
*/
const testRule = async (
ruleName?: keyof Rules,
operator?: string,
value?: string
value?: string,
redirectId?: string
) => {
// If not all data is set, return an error
if (!ruleName || !operator || !value) {
throw new Error("Missing data to test rule");
}

const url =
`/api/v1/rules/${ruleName}/test?operator=${operator}&value=${value}` +
(redirectId ? `&redirectId=${redirectId}` : "");

// We need to unset the default accept-language header just for this request - so that it uses the default language provided by the browser and our language rule can be checked correctly. Because its a post request to `api/v1/rules/${ruleName}/test?operator=${operator}&value=${value}`, we need to set the headers in the data object
const response = await axios
.post(
`/api/v1/rules/${ruleName}/test?operator=${operator}&value=${value}`,
url,
{},
{
transformRequest: [
Expand Down Expand Up @@ -182,7 +188,8 @@ export function useRules(
testRule(
modelData?.value?.selectedRuleKey as keyof Rules,
modelData?.value?.selectedOperator,
modelData?.value?.selectedValue
modelData?.value?.selectedValue,
redirectId?.value
)
.then((passes) => {
userWouldPass.value = passes;
Expand Down

0 comments on commit 2ef3059

Please sign in to comment.