Skip to content

Commit

Permalink
Integration test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRefactoring committed Feb 22, 2025
1 parent f0adcfe commit f02e745
Show file tree
Hide file tree
Showing 2 changed files with 220 additions and 387 deletions.
111 changes: 52 additions & 59 deletions src/version2/avatars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class Avatars {
* **[Permissions](https://developer.atlassian.com/cloud/jira/platform/rest/v2/intro/#permissions) required:** None.
*/
async getAllSystemAvatars<T = Models.SystemAvatars>(
parameters: Parameters.GetAllSystemAvatars,
parameters: Parameters.GetAllSystemAvatars | string,
callback: Callback<T>,
): Promise<void>;
/**
Expand All @@ -28,11 +28,11 @@ export class Avatars {
* **[Permissions](https://developer.atlassian.com/cloud/jira/platform/rest/v2/intro/#permissions) required:** None.
*/
async getAllSystemAvatars<T = Models.SystemAvatars>(
parameters: Parameters.GetAllSystemAvatars,
parameters: Parameters.GetAllSystemAvatars | string,
callback?: never,
): Promise<T>;
async getAllSystemAvatars<T = Models.SystemAvatars>(
parameters: Parameters.GetAllSystemAvatars,
parameters: Parameters.GetAllSystemAvatars | string,
callback?: Callback<T>,
): Promise<void | T> {
const config: RequestConfig = {
Expand Down Expand Up @@ -80,28 +80,10 @@ export class Avatars {

return this.client.sendRequest(config, callback);
}

/**
* Loads a custom avatar for a project, issue type or priority.
*
* Specify the avatar's local file location in the body of the request. Also, include the following headers:
*
* - `X-Atlassian-Token: no-check` To prevent XSRF protection blocking the request, for more information see [Special
* Headers](#special-request-headers).
* - `Content-Type: image/image type` Valid image types are JPEG, GIF, or PNG.
*
* For example:\
* `curl --request POST `
*
* `--user [email protected]:<api_token> `
*
* `--header 'X-Atlassian-Token: no-check' `
*
* `--header 'Content-Type: image/< image_type>' `
*
* `--data-binary "<@/path/to/file/with/your/avatar>" `
*
* `--url 'https://your-domain.atlassian.net/rest/api/2/universal_avatar/type/{type}/owner/{entityId}'`
*
* The avatar is cropped to a square. If no crop parameters are specified, the square originates at the top left of
* the image. The length of the square's sides is set to the smaller of the height or width of the image.
*
Expand All @@ -121,25 +103,6 @@ export class Avatars {
/**
* Loads a custom avatar for a project, issue type or priority.
*
* Specify the avatar's local file location in the body of the request. Also, include the following headers:
*
* - `X-Atlassian-Token: no-check` To prevent XSRF protection blocking the request, for more information see [Special
* Headers](#special-request-headers).
* - `Content-Type: image/image type` Valid image types are JPEG, GIF, or PNG.
*
* For example:\
* `curl --request POST `
*
* `--user [email protected]:<api_token> `
*
* `--header 'X-Atlassian-Token: no-check' `
*
* `--header 'Content-Type: image/< image_type>' `
*
* `--data-binary "<@/path/to/file/with/your/avatar>" `
*
* `--url 'https://your-domain.atlassian.net/rest/api/2/universal_avatar/type/{type}/owner/{entityId}'`
*
* The avatar is cropped to a square. If no crop parameters are specified, the square originates at the top left of
* the image. The length of the square's sides is set to the smaller of the height or width of the image.
*
Expand Down Expand Up @@ -174,6 +137,7 @@ export class Avatars {

return this.client.sendRequest(config, callback);
}

/**
* Deletes an avatar from a project, issue type or priority.
*
Expand All @@ -196,15 +160,16 @@ export class Avatars {

return this.client.sendRequest(config, callback);
}

/**
* Returns the default project, issue type or priority avatar image.
*
* This operation can be accessed anonymously.
*
* **[Permissions](https://developer.atlassian.com/cloud/jira/platform/rest/v2/intro/#permissions) required:** None.
*/
async getAvatarImageByType<T = Models.StreamingResponseBody>(
parameters: Parameters.GetAvatarImageByType,
async getAvatarImageByType<T = Models.AvatarWithDetails>(
parameters: Parameters.GetAvatarImageByType | string,
callback: Callback<T>,
): Promise<void>;
/**
Expand All @@ -214,25 +179,36 @@ export class Avatars {
*
* **[Permissions](https://developer.atlassian.com/cloud/jira/platform/rest/v2/intro/#permissions) required:** None.
*/
async getAvatarImageByType<T = Models.StreamingResponseBody>(
parameters: Parameters.GetAvatarImageByType,
async getAvatarImageByType<T = Models.AvatarWithDetails>(
parameters: Parameters.GetAvatarImageByType | string,
callback?: never,
): Promise<T>;
async getAvatarImageByType<T = Models.StreamingResponseBody>(
parameters: Parameters.GetAvatarImageByType,
async getAvatarImageByType<T = Models.AvatarWithDetails>(
parameters: Parameters.GetAvatarImageByType | string,
callback?: Callback<T>,
): Promise<void | T> {
const type = typeof parameters === 'string' ? parameters : parameters.type;

const config: RequestConfig = {
url: `/rest/api/2/universal_avatar/view/type/${parameters.type}`,
url: `/rest/api/2/universal_avatar/view/type/${type}`,
method: 'GET',
responseType: 'arraybuffer',
params: {
size: parameters.size,
format: parameters.format,
size: typeof parameters !== 'string' ? parameters.size : undefined,
format: typeof parameters !== 'string' ? parameters.format : undefined,
},
};

return this.client.sendRequest(config, callback);
const {
data: avatar,
headers: { 'content-type': contentTypeWithEncoding },
} = await this.client.sendRequestFullResponse<T>(config);

const contentType = contentTypeWithEncoding.split(';')[0].trim();

return this.client.handleSuccessResponse({ contentType, avatar }, callback);
}

/**
* Returns a project, issue type or priority avatar image by ID.
*
Expand All @@ -247,7 +223,7 @@ export class Avatars {
* for at least one project the issue type is used in.
* - For priority avatars, none.
*/
async getAvatarImageByID<T = Models.StreamingResponseBody>(
async getAvatarImageByID<T = Models.AvatarWithDetails>(
parameters: Parameters.GetAvatarImageByID,
callback: Callback<T>,
): Promise<void>;
Expand All @@ -265,25 +241,34 @@ export class Avatars {
* for at least one project the issue type is used in.
* - For priority avatars, none.
*/
async getAvatarImageByID<T = Models.StreamingResponseBody>(
async getAvatarImageByID<T = Models.AvatarWithDetails>(
parameters: Parameters.GetAvatarImageByID,
callback?: never,
): Promise<T>;
async getAvatarImageByID<T = Models.StreamingResponseBody>(
async getAvatarImageByID<T = Models.AvatarWithDetails>(
parameters: Parameters.GetAvatarImageByID,
callback?: Callback<T>,
): Promise<void | T> {
const config: RequestConfig = {
url: `/rest/api/2/universal_avatar/view/type/${parameters.type}/avatar/${parameters.id}`,
method: 'GET',
responseType: 'arraybuffer',
params: {
size: parameters.size,
format: parameters.format,
},
};

return this.client.sendRequest(config, callback);
const {
data: avatar,
headers: { 'content-type': contentTypeWithEncoding },
} = await this.client.sendRequestFullResponse<T>(config);

const contentType = contentTypeWithEncoding.split(';')[0].trim();

return this.client.handleSuccessResponse({ contentType, avatar }, callback);
}

/**
* Returns the avatar image for a project, issue type or priority.
*
Expand All @@ -298,7 +283,7 @@ export class Avatars {
* for at least one project the issue type is used in.
* - For priority avatars, none.
*/
async getAvatarImageByOwner<T = Models.StreamingResponseBody>(
async getAvatarImageByOwner<T = Models.AvatarWithDetails>(
parameters: Parameters.GetAvatarImageByOwner,
callback: Callback<T>,
): Promise<void>;
Expand All @@ -316,23 +301,31 @@ export class Avatars {
* for at least one project the issue type is used in.
* - For priority avatars, none.
*/
async getAvatarImageByOwner<T = Models.StreamingResponseBody>(
async getAvatarImageByOwner<T = Models.AvatarWithDetails>(
parameters: Parameters.GetAvatarImageByOwner,
callback?: never,
): Promise<T>;
async getAvatarImageByOwner<T = Models.StreamingResponseBody>(
async getAvatarImageByOwner<T = Models.AvatarWithDetails>(
parameters: Parameters.GetAvatarImageByOwner,
callback?: Callback<T>,
): Promise<void | T> {
const config: RequestConfig = {
url: `/rest/api/2/universal_avatar/view/type/${parameters.type}/owner/${parameters.entityId}`,
method: 'GET',
responseType: 'arraybuffer',
params: {
size: parameters.size,
format: parameters.format,
},
};

return this.client.sendRequest(config, callback);
const {
data: avatar,
headers: { 'content-type': contentTypeWithEncoding },
} = await this.client.sendRequestFullResponse<T>(config);

const contentType = contentTypeWithEncoding.split(';')[0].trim();

return this.client.handleSuccessResponse({ contentType, avatar }, callback);
}
}
Loading

0 comments on commit f02e745

Please sign in to comment.