Skip to content

Commit

Permalink
Nits, added early return in sendUnique if attribution type is Not Supp
Browse files Browse the repository at this point in the history
  • Loading branch information
rgomezp committed Jun 8, 2020
1 parent 9d829d1 commit 27528f1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/OneSignal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,12 @@ export default class OneSignal {
return;
}
const outcomeAttribution = await outcomesHelper.getAttribution();

if (outcomeAttribution.type === OutcomeAttributionType.NotSupported) {
Log.warn("You are on a free plan. Please upgrade to use this functionality.");
return;
}

// all notifs in attribution window
const { notificationIds } = outcomeAttribution;
// only new notifs that ought to be attributed
Expand Down
3 changes: 1 addition & 2 deletions src/helpers/shared/OutcomesHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ export default class OutcomesHelper {

shouldSendUnique(outcomeAttribution: OutcomeAttribution, notifArr: string[]) {
// we should only send if type is unattributed OR there are notifs to attribute
if (outcomeAttribution.type === OutcomeAttributionType.Unattributed ||
outcomeAttribution.type === OutcomeAttributionType.NotSupported) {
if (outcomeAttribution.type === OutcomeAttributionType.Unattributed) {
return true;
}
return notifArr.length > 0;
Expand Down
2 changes: 1 addition & 1 deletion src/models/OutcomeProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export default interface OutcomeProps {
type: OutcomeAttributionType;
notificationIds: string[];
weight?: number|undefined;
}
}
2 changes: 1 addition & 1 deletion test/unit/public-sdk-apis/sendUniqueOutcome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,4 @@ test("attribution of an outcome with multiple notifications happens correctly",

const sentOutcome = await Database.get<SentUniqueOutcome>("SentUniqueOutcome", OUTCOME_NAME);
t.true(_.isEqual(sentOutcome.notificationIds, notificationArr));
});
});

0 comments on commit 27528f1

Please sign in to comment.