Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDTZ-1049 Set configuration state when connecting/disconnecting Figma teams #111

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/infrastructure/jira/jira-client/jira-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,29 @@ describe('JiraClient', () => {
).rejects.toThrowError(NotFoundOperationError);
});
});

describe('setAppProperty', () => {
const propertyKey = 'property-key';
it('should set app property', async () => {
jest.spyOn(axios, 'put').mockResolvedValue({
status: HttpStatusCode.Ok,
});

await jiraClient.setAppProperty(
propertyKey,
'some value',
connectInstallation,
);

const headers = defaultExpectedRequestHeaders()
.headers.setAccept('application/json')
.setContentType('text/plain');

expect(axios.put).toHaveBeenCalledWith(
`${connectInstallation.baseUrl}/rest/atlassian-connect/1/addons/${connectInstallation.key}/properties/${propertyKey}`,
'some value',
{ headers },
);
});
});
});
26 changes: 26 additions & 0 deletions src/infrastructure/jira/jira-client/jira-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,32 @@ class JiraClient {
});
});

/**
* Sets a connect app property
*
* @see https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-app-properties/#api-rest-atlassian-connect-1-addons-addonkey-properties-propertykey-put
*/
setAppProperty = async (
propertyKey: string,
value: unknown,
connectInstallation: ConnectInstallation,
): Promise<void> =>
withAxiosErrorTranslation(async () => {
const url = new URL(
`/rest/atlassian-connect/1/addons/${connectInstallation.key}/properties/${propertyKey}`,
connectInstallation.baseUrl,
);

await axios.put(url.toString(), value, {
headers: new AxiosHeaders()
.setAuthorization(
this.buildAuthorizationHeader(url, 'PUT', connectInstallation),
)
.setAccept('application/json')
.setContentType('text/plain'),
});
});

private buildAuthorizationHeader(
url: URL,
method: Method,
Expand Down
67 changes: 45 additions & 22 deletions src/infrastructure/jira/jira-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import type {
AttachedDesignUrlV2IssuePropertyValue,
IngestedDesignUrlIssuePropertyValue,
} from './jira-service';
import { jiraService, propertyKeys } from './jira-service';
import {
ConfigurationState,
issuePropertyKeys,
jiraService,
} from './jira-service';

import { NotFoundOperationError } from '../../common/errors';
import type {
Expand Down Expand Up @@ -283,7 +287,7 @@ describe('JiraService', () => {

expect(jiraClient.setIssueProperty).toHaveBeenCalledWith(
issueId,
propertyKeys.ATTACHED_DESIGN_URL,
issuePropertyKeys.ATTACHED_DESIGN_URL,
design.url,
connectInstallation,
);
Expand All @@ -292,7 +296,7 @@ describe('JiraService', () => {
it('should not overwrite the issue property if present', async () => {
jest.spyOn(jiraClient, 'getIssueProperty').mockResolvedValue(
generateGetIssuePropertyResponse({
key: propertyKeys.ATTACHED_DESIGN_URL,
key: issuePropertyKeys.ATTACHED_DESIGN_URL,
}),
);
jest.spyOn(jiraClient, 'setIssueProperty');
Expand Down Expand Up @@ -363,7 +367,7 @@ describe('JiraService', () => {

expect(jiraClient.setIssueProperty).toHaveBeenCalledWith(
issueId,
propertyKeys.ATTACHED_DESIGN_URL_V2,
issuePropertyKeys.ATTACHED_DESIGN_URL_V2,
expectedIssuePropertyValue,
connectInstallation,
);
Expand All @@ -379,7 +383,7 @@ describe('JiraService', () => {
];
jest.spyOn(jiraClient, 'getIssueProperty').mockResolvedValue(
generateGetIssuePropertyResponse({
key: propertyKeys.ATTACHED_DESIGN_URL_V2,
key: issuePropertyKeys.ATTACHED_DESIGN_URL_V2,
value: JSON.stringify(attachedDesignPropertyValues),
}),
);
Expand All @@ -403,7 +407,7 @@ describe('JiraService', () => {

expect(jiraClient.setIssueProperty).toHaveBeenCalledWith(
issueId,
propertyKeys.ATTACHED_DESIGN_URL_V2,
issuePropertyKeys.ATTACHED_DESIGN_URL_V2,
expectedIssuePropertyValue,
connectInstallation,
);
Expand All @@ -412,7 +416,7 @@ describe('JiraService', () => {
it('should not update the issue property url array if the design has already been linked', async () => {
jest.spyOn(jiraClient, 'getIssueProperty').mockResolvedValue(
generateGetIssuePropertyResponse({
key: propertyKeys.ATTACHED_DESIGN_URL_V2,
key: issuePropertyKeys.ATTACHED_DESIGN_URL_V2,
value: JSON.stringify([
{ url: design.url, name: design.displayName },
]),
Expand Down Expand Up @@ -449,7 +453,7 @@ describe('JiraService', () => {

jest.spyOn(jiraClient, 'getIssueProperty').mockResolvedValue(
generateGetIssuePropertyResponse({
key: propertyKeys.ATTACHED_DESIGN_URL_V2,
key: issuePropertyKeys.ATTACHED_DESIGN_URL_V2,
value: JSON.stringify(value),
}),
);
Expand All @@ -463,7 +467,7 @@ describe('JiraService', () => {

expect(jiraClient.setIssueProperty).toBeCalledWith(
issueId,
propertyKeys.ATTACHED_DESIGN_URL_V2,
issuePropertyKeys.ATTACHED_DESIGN_URL_V2,
expectedIssuePropertyValue,
connectInstallation,
);
Expand Down Expand Up @@ -493,7 +497,7 @@ describe('JiraService', () => {

expect(jiraClient.setIssueProperty).toBeCalledWith(
issueId,
propertyKeys.ATTACHED_DESIGN_URL_V2,
issuePropertyKeys.ATTACHED_DESIGN_URL_V2,
expectedIssuePropertyValue,
connectInstallation,
);
Expand Down Expand Up @@ -549,7 +553,7 @@ describe('JiraService', () => {

expect(jiraClient.setIssueProperty).toHaveBeenCalledWith(
issueId,
propertyKeys.INGESTED_DESIGN_URLS,
issuePropertyKeys.INGESTED_DESIGN_URLS,
expectedIssuePropertyValue,
connectInstallation,
);
Expand All @@ -560,7 +564,7 @@ describe('JiraService', () => {
['https://www.figma.com/file/UcmoEBi9SyNOX3SNhXqShY/test-file'];
jest.spyOn(jiraClient, 'getIssueProperty').mockResolvedValue(
generateGetIssuePropertyResponse({
key: propertyKeys.INGESTED_DESIGN_URLS,
key: issuePropertyKeys.INGESTED_DESIGN_URLS,
value: JSON.stringify(ingestedDesignPropertyValues),
}),
);
Expand All @@ -579,7 +583,7 @@ describe('JiraService', () => {

expect(jiraClient.setIssueProperty).toHaveBeenCalledWith(
issueId,
propertyKeys.INGESTED_DESIGN_URLS,
issuePropertyKeys.INGESTED_DESIGN_URLS,
expectedIssuePropertyValue,
connectInstallation,
);
Expand All @@ -588,7 +592,7 @@ describe('JiraService', () => {
it('should not update the ingested designs issue property if the design already exists', async () => {
jest.spyOn(jiraClient, 'getIssueProperty').mockResolvedValue(
generateGetIssuePropertyResponse({
key: propertyKeys.INGESTED_DESIGN_URLS,
key: issuePropertyKeys.INGESTED_DESIGN_URLS,
value: JSON.stringify([design.url]),
}),
);
Expand All @@ -610,7 +614,7 @@ describe('JiraService', () => {

jest.spyOn(jiraClient, 'getIssueProperty').mockResolvedValue(
generateGetIssuePropertyResponse({
key: propertyKeys.INGESTED_DESIGN_URLS,
key: issuePropertyKeys.INGESTED_DESIGN_URLS,
value: JSON.stringify(value),
}),
);
Expand All @@ -624,7 +628,7 @@ describe('JiraService', () => {

expect(jiraClient.setIssueProperty).toBeCalledWith(
issueId,
propertyKeys.INGESTED_DESIGN_URLS,
issuePropertyKeys.INGESTED_DESIGN_URLS,
expectedIssuePropertyValue,
connectInstallation,
);
Expand All @@ -647,7 +651,7 @@ describe('JiraService', () => {

expect(jiraClient.setIssueProperty).toBeCalledWith(
issueId,
propertyKeys.INGESTED_DESIGN_URLS,
issuePropertyKeys.INGESTED_DESIGN_URLS,
expectedIssuePropertyValue,
connectInstallation,
);
Expand Down Expand Up @@ -706,7 +710,7 @@ describe('JiraService', () => {

expect(jiraClient.deleteIssueProperty).toHaveBeenCalledWith(
issueId,
propertyKeys.ATTACHED_DESIGN_URL,
issuePropertyKeys.ATTACHED_DESIGN_URL,
connectInstallation,
);
});
Expand Down Expand Up @@ -798,7 +802,7 @@ describe('JiraService', () => {

jest.spyOn(jiraClient, 'getIssueProperty').mockResolvedValue(
generateGetIssuePropertyResponse({
key: propertyKeys.ATTACHED_DESIGN_URL_V2,
key: issuePropertyKeys.ATTACHED_DESIGN_URL_V2,
value: JSON.stringify(attachedDesignPropertyValues),
}),
);
Expand All @@ -816,7 +820,7 @@ describe('JiraService', () => {

expect(jiraClient.setIssueProperty).toHaveBeenCalledWith(
issueId,
propertyKeys.ATTACHED_DESIGN_URL_V2,
issuePropertyKeys.ATTACHED_DESIGN_URL_V2,
expectedIssuePropertyValue,
connectInstallation,
);
Expand All @@ -832,7 +836,7 @@ describe('JiraService', () => {

jest.spyOn(jiraClient, 'getIssueProperty').mockResolvedValue(
generateGetIssuePropertyResponse({
key: propertyKeys.ATTACHED_DESIGN_URL_V2,
key: issuePropertyKeys.ATTACHED_DESIGN_URL_V2,
value: JSON.stringify(attachedDesignPropertyValues),
}),
);
Expand All @@ -858,7 +862,7 @@ describe('JiraService', () => {
async (value) => {
jest.spyOn(jiraClient, 'getIssueProperty').mockResolvedValue(
generateGetIssuePropertyResponse({
key: propertyKeys.ATTACHED_DESIGN_URL_V2,
key: issuePropertyKeys.ATTACHED_DESIGN_URL_V2,
value: JSON.stringify(value),
}),
);
Expand Down Expand Up @@ -933,4 +937,23 @@ describe('JiraService', () => {
expect(jiraClient.setIssueProperty).not.toHaveBeenCalled();
});
});

describe('setConfigurationStateInAppProperties', () => {
it('should set configuration state in app properties', async () => {
const configurationState = ConfigurationState.CONFIGURED;
const connectInstallation = generateConnectInstallation();
jest.spyOn(jiraClient, 'setAppProperty').mockResolvedValue(undefined);

await jiraService.setConfigurationStateInAppProperties(
configurationState,
connectInstallation,
);

expect(jiraClient.setAppProperty).toHaveBeenCalledWith(
'is-configured',
configurationState.valueOf(),
connectInstallation,
);
});
});
});
Loading