Skip to content

Commit

Permalink
chore: fix muting sign in emails - skip e2e (#2859)
Browse files Browse the repository at this point in the history
* chore: fix muting sign in emails - skip e2e

* chore: fix api version for e2e tests
  • Loading branch information
karolsojko authored Mar 11, 2024
1 parent 41f542d commit 065f356
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/snjs/lib/Application/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
'identifier',
'defaultHost',
'appVersion',
'apiVersion',
]

for (const optionName of requiredOptions) {
Expand Down
20 changes: 20 additions & 0 deletions packages/snjs/lib/Services/Api/ApiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,26 @@ export class LegacyApiService
})
}

async updateSubscriptionSetting(
userUuid: UuidString,
settingName: string,
settingValue: string | null,
sensitive: boolean,
): Promise<HttpResponse<UpdateSettingResponse>> {
const params = {
name: settingName,
value: settingValue,
sensitive: sensitive,
}
return this.tokenRefreshableRequest<UpdateSettingResponse>({
verb: HttpVerb.Put,
url: joinPaths(this.host, Paths.v1.subscriptionSettings(userUuid)),
authentication: this.getSessionAccessToken(),
fallbackErrorMessage: API_MESSAGE_FAILED_UPDATE_SETTINGS,
params,
})
}

async deleteSetting(userUuid: UuidString, settingName: string): Promise<HttpResponse<DeleteSettingResponse>> {
return this.tokenRefreshableRequest<DeleteSettingResponse>({
verb: HttpVerb.Delete,
Expand Down
1 change: 1 addition & 0 deletions packages/snjs/lib/Services/Api/Paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const SettingsPaths = {
setting: (userUuid: string, settingName: string) => `/v1/users/${userUuid}/settings/${settingName}`,
subscriptionSetting: (userUuid: string, settingName: string) =>
`/v1/users/${userUuid}/subscription-settings/${settingName}`,
subscriptionSettings: (userUuid: string) => `/v1/users/${userUuid}/subscription-settings`,
}

const SubscriptionPaths = {
Expand Down
4 changes: 4 additions & 0 deletions packages/snjs/lib/Services/Settings/SNSettingsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export class SettingsService extends AbstractService implements SettingsClientIn
return this.provider.getSubscriptionSetting(name)
}

async updateSubscriptionSetting(name: SettingName, payload: string, sensitive = false) {
return this.provider.updateSetting(name, payload, sensitive)
}

async updateSetting(name: SettingName, payload: string, sensitive = false) {
return this.provider.updateSetting(name, payload, sensitive)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,12 @@ export interface SettingsServerInterface {

getSubscriptionSetting(userUuid: UuidString, settingName: string): Promise<HttpResponse<GetSettingResponse>>

updateSubscriptionSetting(
userUuid: UuidString,
settingName: string,
settingValue: string,
sensitive: boolean,
): Promise<HttpResponse<UpdateSettingResponse>>

deleteSetting(userUuid: UuidString, settingName: string): Promise<HttpResponse<DeleteSettingResponse>>
}
2 changes: 1 addition & 1 deletion packages/snjs/mocha/lib/Applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function createApplicationWithOptions({ identifier, environment, platform
defaultHost: host || Defaults.getDefaultHost(),
appVersion: Defaults.getAppVersion(),
webSocketUrl: Defaults.getDefaultWebSocketUrl(),
apiVersion: ApiVersion.V1,
apiVersion: ApiVersion.v0,
syncCallsThresholdPerMinute,
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ const Email: FunctionComponent<Props> = ({ application }: Props) => {
}
}

const updateSubscriptionSetting = async (settingName: SettingName, payload: string): Promise<boolean> => {
try {
await application.settings.updateSubscriptionSetting(settingName, payload, false)
return true
} catch (e) {
application.alerts.alert(STRING_FAILED_TO_UPDATE_USER_SETTING).catch(console.error)
return false
}
}

const loadSettings = useCallback(async () => {
if (!application.sessions.getUser()) {
return
Expand Down Expand Up @@ -79,7 +89,7 @@ const Email: FunctionComponent<Props> = ({ application }: Props) => {
previousValue === MuteSignInEmailsOption.Muted ? MuteSignInEmailsOption.NotMuted : MuteSignInEmailsOption.Muted
setSignInEmailsMutedValue(newValue)

const updateResult = await updateSetting(
const updateResult = await updateSubscriptionSetting(
SettingName.create(SettingName.NAMES.MuteSignInEmails).getValue(),
newValue,
)
Expand Down

0 comments on commit 065f356

Please sign in to comment.