Skip to content

Commit

Permalink
chore: initial set notifications settings
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleSamtoshi committed Sep 13, 2023
1 parent d468d73 commit 7c1d2bd
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 0 deletions.
Empty file added bats
Empty file.
29 changes: 29 additions & 0 deletions dev/apollo-federation/supergraph.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ type AccountUpdateDisplayCurrencyPayload
errors: [Error!]!
}

input AccountUpdatePushNotificationSettingsInput
@join__type(graph: PUBLIC)
{
notificationSettings: [PushNotifcationSettingsInput]!
notificationsEnabled: Boolean!
}

type AccountUpdatePushNotificationSettingsPayload
@join__type(graph: PUBLIC)
{
account: ConsumerAccount
errors: [Error!]!
}

"""An Opaque Bearer token"""
scalar AuthToken
@join__type(graph: PUBLIC)
Expand Down Expand Up @@ -818,6 +832,7 @@ type Mutation
accountDelete: AccountDeletePayload!
accountUpdateDefaultWalletId(input: AccountUpdateDefaultWalletIdInput!): AccountUpdateDefaultWalletIdPayload!
accountUpdateDisplayCurrency(input: AccountUpdateDisplayCurrencyInput!): AccountUpdateDisplayCurrencyPayload!
accountUpdatePushNotificationSettings(input: AccountUpdatePushNotificationSettingsInput!): AccountUpdatePushNotificationSettingsPayload!
callbackEndpointAdd(input: CallbackEndpointAddInput!): CallbackEndpointAddPayload!
callbackEndpointDelete(input: CallbackEndpointDeleteInput!): SuccessPayload!
captchaCreateChallenge: CaptchaCreateChallengePayload!
Expand Down Expand Up @@ -1220,6 +1235,20 @@ type PublicWallet
walletCurrency: WalletCurrency!
}

input PushNotifcationSettingsInput
@join__type(graph: PUBLIC)
{
disabledSubtypes: [PushNotificationSubType]!
enabled: Boolean!
type: PushNotificationType!
}

scalar PushNotificationSubType
@join__type(graph: PUBLIC)

scalar PushNotificationType
@join__type(graph: PUBLIC)

type Query
@join__type(graph: PUBLIC)
{
Expand Down
2 changes: 2 additions & 0 deletions src/domain/primitives/index.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type MilliSeconds = number & { readonly brand: unique symbol }
type Days = number & { readonly brand: unique symbol }
type JwtToken = string & { readonly brand: unique symbol } // short lived asymmetric token from oathkeeper
type Memo = string & { readonly brand: unique symbol }
type PushNotificationType = string & { readonly brand: unique symbol }
type PushNotificationSubType = string & { readonly brand: unique symbol }

type XOR<T1, T2> =
| (T1 & { [k in Exclude<keyof T2, keyof T1>]?: never })
Expand Down
3 changes: 3 additions & 0 deletions src/graphql/public/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import UserTotpDeleteMutation from "@graphql/public/root/mutation/user-totp-dele

import CallbackEndpointAdd from "./root/mutation/callback-endpoint-add"
import CallbackEndpointDelete from "./root/mutation/callback-endpoint-delete"
import AccountUpdatePushNotificationSettingsMutation from "./root/mutation/account-update-push-notification-settings"

// TODO: // const fields: { [key: string]: GraphQLFieldConfig<any, GraphQLPublicContext> }
export const mutationFields = {
Expand Down Expand Up @@ -86,6 +87,8 @@ export const mutationFields = {
userContactUpdateAlias: UserContactUpdateAliasMutation,
accountUpdateDefaultWalletId: AccountUpdateDefaultWalletIdMutation,
accountUpdateDisplayCurrency: AccountUpdateDisplayCurrencyMutation,
accountUpdatePushNotificationSettings:
AccountUpdatePushNotificationSettingsMutation,
accountDelete: AccountDeleteMutation,
feedbackSubmit: FeedbackSubmitMutation,

Expand Down
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
21 changes: 21 additions & 0 deletions src/graphql/public/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ type AccountUpdateDisplayCurrencyPayload {
errors: [Error!]!
}

input AccountUpdatePushNotificationSettingsInput {
notificationSettings: [PushNotifcationSettingsInput]!
notificationsEnabled: Boolean!
}

type AccountUpdatePushNotificationSettingsPayload {
account: ConsumerAccount
errors: [Error!]!
}

"""An Opaque Bearer token"""
scalar AuthToken

Expand Down Expand Up @@ -622,6 +632,7 @@ type Mutation {
accountDelete: AccountDeletePayload!
accountUpdateDefaultWalletId(input: AccountUpdateDefaultWalletIdInput!): AccountUpdateDefaultWalletIdPayload!
accountUpdateDisplayCurrency(input: AccountUpdateDisplayCurrencyInput!): AccountUpdateDisplayCurrencyPayload!
accountUpdatePushNotificationSettings(input: AccountUpdatePushNotificationSettingsInput!): AccountUpdatePushNotificationSettingsPayload!
callbackEndpointAdd(input: CallbackEndpointAddInput!): CallbackEndpointAddPayload!
callbackEndpointDelete(input: CallbackEndpointDeleteInput!): SuccessPayload!
captchaCreateChallenge: CaptchaCreateChallengePayload!
Expand Down Expand Up @@ -959,6 +970,16 @@ type PublicWallet {
walletCurrency: WalletCurrency!
}

input PushNotifcationSettingsInput {
disabledSubtypes: [PushNotificationSubType]!
enabled: Boolean!
type: PushNotificationType!
}

scalar PushNotificationSubType

scalar PushNotificationType

type Query {
accountDefaultWallet(username: Username!, walletCurrency: WalletCurrency): PublicWallet!
btcPrice(currency: DisplayCurrency! = "USD"): Price @deprecated(reason: "Deprecated in favor of realtimePrice")
Expand Down
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 src/graphql/shared/types/scalar/push-notification-sub-type.ts
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
28 changes: 28 additions & 0 deletions src/graphql/shared/types/scalar/push-notification-type.ts
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 test/bats/gql/account-update-push-notification-settings.gql
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
}
}
}
44 changes: 44 additions & 0 deletions test/bats/push-notification-settings.bats
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
}

0 comments on commit 7c1d2bd

Please sign in to comment.