-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
162608a
commit 0c92c5e
Showing
11 changed files
with
244 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
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 |
---|---|---|
|
@@ -42,4 +42,5 @@ export interface Params { | |
*/ | ||
location_id?: string; | ||
creation_id?: string; | ||
share_to_feed?: boolean; | ||
} |
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 |
---|---|---|
|
@@ -94,4 +94,6 @@ export enum MediaType { | |
VIDEO = 'VIDEO', | ||
|
||
CAROUSEL = 'CAROUSEL', | ||
|
||
REEL = 'REELS', | ||
} |
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,66 @@ | ||
import { AbstractPostPageMediaRequest, MediaType } from './AbstractPostPageMediaRequest'; | ||
|
||
/** | ||
* * A request that creates a new Reels Media container. | ||
* * | ||
* * @author Tiago Grosso <tiagogrosso99@gmail.com> | ||
* * @since `next.release` | ||
* */ | ||
export class PostPageReelMediaRequest extends AbstractPostPageMediaRequest { | ||
/** | ||
* The constructor | ||
* | ||
* @param accessToken the access token. | ||
* @param pageId the page id. | ||
* @param videoUrl the video URL. | ||
* @param caption the caption. | ||
* @param thumbOffset the thumbnail offset. | ||
* @param shareToFeed whether the reel should be shared in the feed as well. | ||
* @param locationId the location id. | ||
*/ | ||
constructor( | ||
accessToken: string, | ||
pageId: string, | ||
videoUrl: string, | ||
caption?: string, | ||
thumbOffset?: number, | ||
shareToFeed?: boolean, | ||
locationId?: string | ||
) { | ||
super(accessToken, pageId, caption, locationId); | ||
this.params.video_url = videoUrl; | ||
this.params.thumb_offset = thumbOffset; | ||
this.params.share_to_feed = shareToFeed; | ||
} | ||
|
||
/** | ||
* Sets the thumbnail offset time in the request. | ||
* | ||
* @param thumbOffset the thumbnail offset time. | ||
* | ||
* @returns this object, for chained invocation. | ||
*/ | ||
public withThumbOffset(thumbOffset: number): this { | ||
this.params.thumb_offset = thumbOffset; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets whether the reel should be shared in the feed as well. | ||
* | ||
* @param shareToFeed whether the reel should be shared in the feed as well. | ||
* | ||
* @returns this object, for chained invocation. | ||
*/ | ||
public withShareToFeed(shareToFeed: boolean): this { | ||
this.params.share_to_feed = shareToFeed; | ||
return this; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected mediaType(): MediaType | undefined { | ||
return MediaType.REEL; | ||
} | ||
} |
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
60 changes: 60 additions & 0 deletions
60
src/test/requests/page/media/PostPageReelMediaRequest.test.ts
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,60 @@ | ||
import axios from 'axios'; | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import { Constants } from '../../../../main/Constants'; | ||
import { CreatedObjectIdResponse } from '../../../../main/requests/common/CreatedObjectIdResponse'; | ||
import { PostPageReelMediaRequest } from '../../../../main/requests/page/media/PostPageReelMediaRequest'; | ||
import { TestConstants } from '../../../TestConstants'; | ||
|
||
describe('PostPageReelMediaRequest.', () => { | ||
const request: PostPageReelMediaRequest = new PostPageReelMediaRequest( | ||
TestConstants.ACCESS_TOKEN, | ||
TestConstants.PAGE_ID, | ||
TestConstants.MEDIA_URL, | ||
TestConstants.CAPTION, | ||
TestConstants.THUMB_OFFSET, | ||
TestConstants.SHARE_TO_FEED, | ||
TestConstants.LOCATION_ID | ||
); | ||
const requestBare: PostPageReelMediaRequest = new PostPageReelMediaRequest( | ||
TestConstants.ACCESS_TOKEN, | ||
TestConstants.PAGE_ID, | ||
TestConstants.MEDIA_URL | ||
); | ||
|
||
it('Builds the config', () => { | ||
expect(request.config().method).toEqual('POST'); | ||
expect(request.config().url).toEqual(`/${TestConstants.PAGE_ID}/media`); | ||
expect(request.config().params.video_url).toEqual(TestConstants.MEDIA_URL); | ||
expect(request.config().params.caption).toEqual(TestConstants.CAPTION); | ||
expect(request.config().params.thumb_offset).toEqual(TestConstants.THUMB_OFFSET); | ||
expect(request.config().params.share_to_feed).toEqual(TestConstants.SHARE_TO_FEED); | ||
expect(request.config().params.location_id).toEqual(TestConstants.LOCATION_ID); | ||
}); | ||
|
||
it('Adds params request config', () => { | ||
expect(requestBare.config().params.video_url).toEqual(TestConstants.MEDIA_URL); | ||
expect(requestBare.config().params.caption).toBeUndefined(); | ||
expect(requestBare.config().params.location_id).toBeUndefined(); | ||
expect(requestBare.config().params.share_to_feed).toBeUndefined(); | ||
expect(requestBare.config().params.thumb_offset).toBeUndefined(); | ||
|
||
requestBare.withCaption(TestConstants.CAPTION); | ||
requestBare.withLocationId(TestConstants.LOCATION_ID); | ||
requestBare.withThumbOffset(TestConstants.THUMB_OFFSET); | ||
requestBare.withShareToFeed(TestConstants.SHARE_TO_FEED); | ||
|
||
expect(requestBare.config().params.caption).toEqual(TestConstants.CAPTION); | ||
expect(requestBare.config().params.thumb_offset).toEqual(TestConstants.THUMB_OFFSET); | ||
expect(requestBare.config().params.location_id).toEqual(TestConstants.LOCATION_ID); | ||
expect(request.config().params.share_to_feed).toEqual(TestConstants.SHARE_TO_FEED); | ||
}); | ||
|
||
const mock = new MockAdapter(axios); | ||
mock.onPost(`${Constants.API_URL}/${TestConstants.PAGE_ID}/media`).reply(200, { id: TestConstants.CONTAINER_ID }); | ||
it('Parses the response', () => { | ||
expect.assertions(1); | ||
return request.execute().then((response) => { | ||
expect(response).toEqual(new CreatedObjectIdResponse({ id: TestConstants.CONTAINER_ID })); | ||
}); | ||
}); | ||
}); |