-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: initial set notifications settings
- Loading branch information
1 parent
d468d73
commit 7c1d2bd
Showing
11 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/graphql/public/root/mutation/account-update-push-notification-settings.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { GT } from "@graphql/index" | ||
|
||
import PushNotificationType from "@graphql/shared/types/scalar/push-notification-type" | ||
import PushNotificationSubType from "@graphql/shared/types/scalar/push-notification-sub-type" | ||
import AccountUpdatePushNotificationSettingsPayload from "@graphql/public/types/payload/account-update-push-notification-settings" | ||
|
||
const PushNotifcationSettingsInput = GT.Input({ | ||
name: "PushNotifcationSettingsInput", | ||
fields: () => ({ | ||
type: { type: GT.NonNull(PushNotificationType) }, | ||
enabled: { type: GT.NonNull(GT.Boolean) }, | ||
disabledSubtypes: { type: GT.NonNull(GT.List(PushNotificationSubType)) }, | ||
}), | ||
}) | ||
|
||
const AccountUpdatePushNotificationSettingsInput = GT.Input({ | ||
name: "AccountUpdatePushNotificationSettingsInput", | ||
fields: () => ({ | ||
notificationsEnabled: { type: GT.NonNull(GT.Boolean) }, | ||
notificationSettings: { | ||
type: GT.NonNull(GT.List(PushNotifcationSettingsInput)), | ||
}, | ||
}), | ||
}) | ||
|
||
const AccountUpdatePushNotificationSettingsMutation = GT.Field({ | ||
extensions: { | ||
complexity: 120, | ||
}, | ||
type: GT.NonNull(AccountUpdatePushNotificationSettingsPayload), | ||
args: { | ||
input: { type: GT.NonNull(AccountUpdatePushNotificationSettingsInput) }, | ||
}, | ||
resolve: async (_, args, { domainAccount }: { domainAccount: Account }) => { | ||
return { | ||
errors: [], | ||
} | ||
}, | ||
}) | ||
|
||
export default AccountUpdatePushNotificationSettingsMutation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/graphql/public/types/payload/account-update-push-notification-settings.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { GT } from "@graphql/index" | ||
|
||
import IError from "../../../shared/types/abstract/error" | ||
import ConsumerAccount from "../object/consumer-account" | ||
|
||
const AccountUpdatePushNotificationSettingsPayload = GT.Object({ | ||
name: "AccountUpdatePushNotificationSettingsPayload", | ||
fields: () => ({ | ||
errors: { | ||
type: GT.NonNullList(IError), | ||
}, | ||
account: { | ||
type: ConsumerAccount, | ||
}, | ||
}), | ||
}) | ||
|
||
export default AccountUpdatePushNotificationSettingsPayload |
30 changes: 30 additions & 0 deletions
30
src/graphql/shared/types/scalar/push-notification-sub-type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { InputValidationError } from "@graphql/error" | ||
import { GT } from "@graphql/index" | ||
|
||
const PushNotificationSubType = GT.Scalar({ | ||
name: "PushNotificationSubType", | ||
parseValue(value) { | ||
if (typeof value !== "string") { | ||
return new InputValidationError({ | ||
message: "Invalid type for PushNotificationSubType", | ||
}) | ||
} | ||
return validPushNotificationSubType(value) | ||
}, | ||
parseLiteral(ast) { | ||
if (ast.kind === GT.Kind.STRING) { | ||
return validPushNotificationSubType(ast.value) | ||
} | ||
return new InputValidationError({ | ||
message: "Invalid type for PushNotificationSubType", | ||
}) | ||
}, | ||
}) | ||
|
||
function validPushNotificationSubType( | ||
value: string, | ||
): PushNotificationSubType | InputValidationError { | ||
return value as PushNotificationSubType | ||
} | ||
|
||
export default PushNotificationSubType |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { InputValidationError } from "@graphql/error" | ||
import { GT } from "@graphql/index" | ||
|
||
const PushNotificationType = GT.Scalar({ | ||
name: "PushNotificationType", | ||
parseValue(value) { | ||
if (typeof value !== "string") { | ||
return new InputValidationError({ | ||
message: "Invalid type for PushNotificationType", | ||
}) | ||
} | ||
return validPushNotificationType(value) | ||
}, | ||
parseLiteral(ast) { | ||
if (ast.kind === GT.Kind.STRING) { | ||
return validPushNotificationType(ast.value) | ||
} | ||
return new InputValidationError({ message: "Invalid type for PushNotificationType" }) | ||
}, | ||
}) | ||
|
||
function validPushNotificationType( | ||
value: string, | ||
): PushNotificationType | InputValidationError { | ||
return value as PushNotificationType | ||
} | ||
|
||
export default PushNotificationType |
10 changes: 10 additions & 0 deletions
10
test/bats/gql/account-update-push-notification-settings.gql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
mutation accountUpdatePushNotificationSettings($input: AccountUpdatePushNotificationSettingsInput!) { | ||
accountUpdatePushNotificationSettings(input: $input) { | ||
errors { | ||
message | ||
} | ||
account { | ||
defaultWalletId | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env bats | ||
|
||
load "helpers/setup-and-teardown" | ||
|
||
setup_file() { | ||
clear_cache | ||
reset_redis | ||
|
||
bitcoind_init | ||
start_trigger | ||
start_server | ||
|
||
initialize_user_from_onchain "$ALICE_TOKEN_NAME" "$ALICE_PHONE" "$CODE" | ||
} | ||
|
||
teardown_file() { | ||
stop_trigger | ||
stop_server | ||
} | ||
|
||
|
||
@test "push-notification-settings: set and get" { | ||
token_name="$ALICE_TOKEN_NAME" | ||
|
||
# notification_setting="{type: \"Circles\", enabled: false, disabledSubtypes: []}" | ||
notification_setting=$( | ||
jq -n \ | ||
--arg type "Circles" \ | ||
--argjson enabled false \ | ||
--argjson disabledSubtypes "[]" \ | ||
'{type: $type, enabled: $enabled, disabledSubtypes: $disabledSubtypes}' | ||
) | ||
|
||
variables=$( | ||
jq -n \ | ||
--argjson notification_setting "$notification_setting" \ | ||
'{input: {notificationsEnabled: true, notificationSettings: [$notification_setting]}}' | ||
) | ||
|
||
exec_graphql "$token_name" 'account-update-push-notification-settings' "$variables" | ||
|
||
wallet_id="$(graphql_output '.data.accountUpdatePushNotificationSettings.account.defaultWalletId')" | ||
[[ "$wallet_id" == "1232" ]] || exit 1 | ||
} |