-
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 #43 from remarkablemark/feat/messages-schedule-create
feat: add messages schedule create
- Loading branch information
Showing
10 changed files
with
160 additions
and
6 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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * as schedule from './schedule' | ||
export * from './send' | ||
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,98 @@ | ||
import { post } from '../../common/request' | ||
import { create } from '.' | ||
import type { MessagesScheduleCreateObject } from './types' | ||
|
||
jest.mock('../../common/request') | ||
const mockedPost = jest.mocked(post) | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
describe('/messages/schedule/create', () => { | ||
const apiUrl = 'https://rest.iad-01.braze.com' | ||
const apiKey = 'apiKey' | ||
|
||
const body: MessagesScheduleCreateObject = { | ||
broadcast: false, | ||
external_user_ids: ['external_user_identifiers'], | ||
user_aliases: [ | ||
{ | ||
alias_name: 'example_name', | ||
alias_label: 'example_label', | ||
}, | ||
], | ||
segment_id: 'segment_identifiers', | ||
audience: { | ||
AND: [ | ||
{ | ||
custom_attribute: { | ||
custom_attribute_name: 'eye_color', | ||
comparison: 'equals', | ||
value: 'blue', | ||
}, | ||
}, | ||
{ | ||
custom_attribute: { | ||
custom_attribute_name: 'favorite_foods', | ||
comparison: 'includes_value', | ||
value: 'pizza', | ||
}, | ||
}, | ||
{ | ||
OR: [ | ||
{ | ||
custom_attribute: { | ||
custom_attribute_name: 'last_purchase_time', | ||
comparison: 'less_than_x_days_ago', | ||
value: 2, | ||
}, | ||
}, | ||
{ | ||
push_subscription_status: { | ||
comparison: 'is', | ||
value: 'opted_in', | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
email_subscription_status: { | ||
comparison: 'is_not', | ||
value: 'subscribed', | ||
}, | ||
}, | ||
{ | ||
last_used_app: { | ||
comparison: 'after', | ||
value: '2019-07-22T13:17:55+0000', | ||
}, | ||
}, | ||
], | ||
}, | ||
campaign_id: 'campaign_identifier', | ||
send_id: 'send_identifier', | ||
override_messaging_limits: false, | ||
recipient_subscription_state: 'subscribed', | ||
schedule: { | ||
time: '', | ||
in_local_time: true, | ||
at_optimal_time: true, | ||
}, | ||
messages: {}, | ||
} | ||
|
||
const data = {} | ||
|
||
it('calls request with url and body', async () => { | ||
mockedPost.mockResolvedValueOnce(data) | ||
expect(await create(apiUrl, apiKey, body)).toBe(data) | ||
expect(mockedPost).toBeCalledWith(`${apiUrl}/messages/schedule/create`, 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,29 @@ | ||
import { post } from '../../common/request' | ||
import type { MessagesScheduleCreateObject } from './types' | ||
|
||
/** | ||
* Create scheduled messages. | ||
* | ||
* Use this endpoint to send messages directly from the API. | ||
* | ||
* {@link https://www.braze.com/docs/api/endpoints/messaging/schedule_messages/post_schedule_messages/} | ||
* | ||
* @param apiUrl - Braze REST endpoint. | ||
* @param apiKey - Braze API key. | ||
* @param body - Request parameters. | ||
* @returns - Braze response. | ||
*/ | ||
export function create(apiUrl: string, apiKey: string, body: MessagesScheduleCreateObject) { | ||
const options = { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${apiKey}`, | ||
}, | ||
} | ||
|
||
return post(`${apiUrl}/messages/schedule/create`, body, options) as Promise<{ | ||
dispatch_id: string | ||
schedule_id: string | ||
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,2 @@ | ||
export * from './create' | ||
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,13 @@ | ||
import type { ScheduleObject } from '../../common/types' | ||
import type { MessagesSendObject } from '../types' | ||
|
||
/** | ||
* Request body for create scheduled messages. | ||
* | ||
* {@link https://www.braze.com/docs/api/endpoints/messaging/schedule_messages/post_schedule_messages/#request-body} | ||
*/ | ||
export interface MessagesScheduleCreateObject | ||
extends Omit<MessagesSendObject, 'override_frequency_capping'> { | ||
override_messaging_limits?: boolean | ||
schedule: ScheduleObject | ||
} |
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