-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for custom headers field for Drafts and Messages (#553)
This PR adds support to the custom headers field used to attach headers to message and draft objects. Not to be confused with custom headers to Nylas API requests, completed by #552.
- Loading branch information
1 parent
618d8bd
commit 5157373
Showing
3 changed files
with
115 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import APIClient from '../../src/apiClient'; | |
import { Drafts } from '../../src/resources/drafts'; | ||
import { createReadableStream, MockedFormData } from '../testUtils'; | ||
import { CreateAttachmentRequest } from '../../src/models/attachments'; | ||
import { objKeysToCamelCase } from '../../src/utils'; | ||
jest.mock('../src/apiClient'); | ||
|
||
// Mock the FormData constructor | ||
|
@@ -33,6 +34,100 @@ describe('Drafts', () => { | |
apiClient.request.mockResolvedValue({}); | ||
}); | ||
|
||
describe('deserializing', () => { | ||
it('should return a draft object as expected', () => { | ||
const apiDraft = { | ||
body: 'Hello, I just sent a message using Nylas!', | ||
cc: [ | ||
{ | ||
email: '[email protected]', | ||
}, | ||
], | ||
attachments: [ | ||
{ | ||
content_type: 'text/calendar', | ||
id: '4kj2jrcoj9ve5j9yxqz5cuv98', | ||
size: 1708, | ||
}, | ||
], | ||
folders: ['8l6c4d11y1p4dm4fxj52whyr9', 'd9zkcr2tljpu3m4qpj7l2hbr0'], | ||
from: [ | ||
{ | ||
name: 'Daenerys Targaryen', | ||
email: '[email protected]', | ||
}, | ||
], | ||
grant_id: '41009df5-bf11-4c97-aa18-b285b5f2e386', | ||
id: '5d3qmne77v32r8l4phyuksl2x', | ||
object: 'draft', | ||
reply_to: [ | ||
{ | ||
name: 'Daenerys Targaryen', | ||
email: '[email protected]', | ||
}, | ||
], | ||
snippet: 'Hello, I just sent a message using Nylas!', | ||
starred: true, | ||
subject: 'Hello from Nylas!', | ||
thread_id: '1t8tv3890q4vgmwq6pmdwm8qgsaer', | ||
to: [ | ||
{ | ||
name: 'Jon Snow', | ||
email: '[email protected]', | ||
}, | ||
], | ||
date: 1705084742, | ||
created_at: 1705084926, | ||
}; | ||
|
||
const draft = objKeysToCamelCase(apiDraft); | ||
|
||
expect(draft).toEqual({ | ||
body: 'Hello, I just sent a message using Nylas!', | ||
cc: [ | ||
{ | ||
email: '[email protected]', | ||
}, | ||
], | ||
attachments: [ | ||
{ | ||
contentType: 'text/calendar', | ||
id: '4kj2jrcoj9ve5j9yxqz5cuv98', | ||
size: 1708, | ||
}, | ||
], | ||
folders: ['8l6c4d11y1p4dm4fxj52whyr9', 'd9zkcr2tljpu3m4qpj7l2hbr0'], | ||
from: [ | ||
{ | ||
name: 'Daenerys Targaryen', | ||
email: '[email protected]', | ||
}, | ||
], | ||
grantId: '41009df5-bf11-4c97-aa18-b285b5f2e386', | ||
id: '5d3qmne77v32r8l4phyuksl2x', | ||
object: 'draft', | ||
replyTo: [ | ||
{ | ||
name: 'Daenerys Targaryen', | ||
email: '[email protected]', | ||
}, | ||
], | ||
snippet: 'Hello, I just sent a message using Nylas!', | ||
starred: true, | ||
subject: 'Hello from Nylas!', | ||
threadId: '1t8tv3890q4vgmwq6pmdwm8qgsaer', | ||
to: [ | ||
{ | ||
name: 'Jon Snow', | ||
email: '[email protected]', | ||
}, | ||
], | ||
date: 1705084742, | ||
createdAt: 1705084926, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('list', () => { | ||
it('should call apiClient.request with the correct params', async () => { | ||
await drafts.list({ | ||
|