-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from remarkablemark/feat/subscription-status-set
feat: add subscription status set
- Loading branch information
Showing
9 changed files
with
121 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * as status from './status' |
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,2 @@ | ||
export * from './set' | ||
export * from './types' |
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,52 @@ | ||
import { post } from '../../common/request' | ||
import { set } from '.' | ||
import type { SubscriptionStatusSetObject } from './types' | ||
|
||
jest.mock('../../common/request') | ||
const mockedPost = jest.mocked(post) | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
describe('/subscription/status/set', () => { | ||
const apiUrl = 'https://rest.iad-01.braze.com' | ||
const apiKey = 'apiKey' | ||
const data = {} | ||
|
||
it('calls SMS request with url and body', async () => { | ||
mockedPost.mockResolvedValueOnce(data) | ||
const body: SubscriptionStatusSetObject = { | ||
subscription_group_id: 'subscription_group_identifier', | ||
subscription_state: 'unsubscribed', | ||
external_id: ['external_identifier'], | ||
email: ['example1@email.com', 'example2@email.com'], | ||
} | ||
expect(await set(apiUrl, apiKey, body)).toBe(data) | ||
expect(mockedPost).toBeCalledWith(`${apiUrl}/subscription/status/set`, body, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${apiKey}`, | ||
}, | ||
}) | ||
expect(mockedPost).toBeCalledTimes(1) | ||
}) | ||
|
||
it('calls email request with url and body', async () => { | ||
mockedPost.mockResolvedValueOnce(data) | ||
const body: SubscriptionStatusSetObject = { | ||
subscription_group_id: 'subscription_group_identifier', | ||
subscription_state: 'subscribed', | ||
external_id: ['external_identifier'], | ||
phone: ['+12223334444', '+11112223333'], | ||
} | ||
expect(await set(apiUrl, apiKey, body)).toBe(data) | ||
expect(mockedPost).toBeCalledWith(`${apiUrl}/subscription/status/set`, body, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${apiKey}`, | ||
}, | ||
}) | ||
expect(mockedPost).toBeCalledTimes(1) | ||
}) | ||
}) |
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,27 @@ | ||
import { post } from '../../common/request' | ||
import type { SubscriptionStatusSetObject } from './types' | ||
|
||
/** | ||
* Update user’s subscription group status. | ||
* | ||
* Use these endpoints to batch update the subscription state of up to 50 users on the Braze dashboard. | ||
* | ||
* {@link https://www.braze.com/docs/api/endpoints/subscription_groups/post_update_user_subscription_group_status/} | ||
* | ||
* @param apiUrl - Braze REST endpoint. | ||
* @param apiKey - Braze API key. | ||
* @param body - Request parameters. | ||
* @returns - Braze response. | ||
*/ | ||
export function set(apiUrl: string, apiKey: string, body: SubscriptionStatusSetObject) { | ||
const options = { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${apiKey}`, | ||
}, | ||
} | ||
|
||
return post(`${apiUrl}/subscription/status/set`, body, options) as Promise<{ | ||
message: 'success' | string | ||
}> | ||
} |
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,20 @@ | ||
/** | ||
* Request body for update user’s subscription group status. | ||
* | ||
* {@link https://www.braze.com/docs/api/endpoints/subscription_groups/post_update_user_subscription_group_status/#request-body} | ||
*/ | ||
export type SubscriptionStatusSetObject = SubscriptionStatusWithPhone | SubscriptionStatusWithEmail | ||
|
||
interface SubscriptionStatus { | ||
subscription_group_id: string | ||
subscription_state: 'unsubscribed' | 'subscribed' | ||
external_id: string[] | ||
} | ||
|
||
interface SubscriptionStatusWithPhone extends SubscriptionStatus { | ||
phone: string[] | ||
} | ||
|
||
interface SubscriptionStatusWithEmail extends SubscriptionStatus { | ||
email: string[] | ||
} |