Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(assets): Allow getting of asset by ID (#93)
* feature(assets): Allow getting of asset by ID * feature(get asset): EpochTimestamp to number * feature(get assets): Replaced id with blank uid * feature(assets): Added to readme
- Loading branch information
1 parent
6bed99e
commit f7020d2
Showing
9 changed files
with
157 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export type Asset = { | ||
srcName: string; | ||
revisionNumber: number; | ||
bucketID: string; | ||
label: string; | ||
mimeType: string; | ||
type: string; | ||
userID: string; | ||
thumbFile: string; | ||
folderID: string; | ||
file: string; | ||
createdDate: number; | ||
name: string; | ||
subType: string | null; | ||
id: string; | ||
thumbURL: string; | ||
publishStatus: string; | ||
status: string; | ||
timestamp: number; | ||
}; |
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,49 @@ | ||
import { ClientConnection } from 'message-event-channel'; | ||
import { Assets } from './Assets'; | ||
|
||
const asset = { | ||
srcName: 'an-image.jpg', | ||
revisionNumber: 8, | ||
bucketID: '00000000-0000-0000-0000-000000000000', | ||
label: 'an-image.jpg', | ||
mimeType: 'image/jpeg', | ||
type: 'image', | ||
userID: '00000000-0000-0000-0000-000000000000', | ||
thumbFile: '00000000-0000-0000-0000-000000000000', | ||
folderID: '00000000-0000-0000-0000-000000000000', | ||
file: '00000000-0000-0000-0000-000000000000', | ||
createdDate: 1683798022161, | ||
name: 'an-image', | ||
subType: null, | ||
id: '00000000-0000-0000-0000-000000000000', | ||
thumbURL: 'https://thumbs.amplience.net/r/00000000-0000-0000-0000-000000000000', | ||
publishStatus: 'PUBLISHED', | ||
status: 'active', | ||
timestamp: 1688563779803, | ||
}; | ||
|
||
describe('Assets', () => { | ||
let connection: ClientConnection; | ||
let assets: Assets; | ||
|
||
beforeEach(() => { | ||
connection = new ClientConnection(); | ||
assets = new Assets(connection); | ||
}); | ||
|
||
describe('getById', () => { | ||
it('Should get asset', async () => { | ||
jest.spyOn(connection, 'request').mockResolvedValue(asset); | ||
|
||
const response = await assets.getById('123-456-789'); | ||
|
||
expect(response).toBe(asset); | ||
}); | ||
it('Should return an error if get asset fails', () => { | ||
jest.spyOn(connection, 'request').mockRejectedValue(new Error('Could not get asset')); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
expect(assets.getById('123-456-789')).rejects.toThrow('Could not get asset'); | ||
}); | ||
}); | ||
}); |
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,33 @@ | ||
import { ClientConnection } from 'message-event-channel'; | ||
import { ASSETS } from '../constants/Events'; | ||
import { Asset } from './Asset'; | ||
|
||
export class Assets { | ||
/** | ||
* Assets - Used for retrieving assets. | ||
* | ||
* @param connection message-event-channel connection | ||
*/ | ||
constructor(private connection: ClientConnection) {} | ||
|
||
/** | ||
* Get an asset by id | ||
* | ||
* | ||
* ### Example | ||
* ```typescript | ||
* try { | ||
* const asset = await sdk.asset.getById('123-456'); | ||
* | ||
* console.log(asset) | ||
* } catch (e) { | ||
* // Could not get asset | ||
* ... | ||
* } | ||
* | ||
* ``` | ||
*/ | ||
async getById(id: string): Promise<Asset | Error> { | ||
return this.connection.request(ASSETS.GET_BY_ID, id); | ||
} | ||
} |
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