Skip to content

Commit 8f9782a

Browse files
src: cleanup ext_figma_for_jira_use_file_webhooks feature flag (#264)
* cache launchdarkly client * clean up feature flag checks and update tests
1 parent dd500ec commit 8f9782a

9 files changed

Lines changed: 33 additions & 67 deletions

src/config/launch_darkly.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ import { getLogger } from '../infrastructure';
55

66
import { getConfig } from '.';
77

8+
let cachedClient: LDClient | null = null;
9+
810
export async function getLDClient(): Promise<LDClient | null> {
9-
const ldSecretKey = getLaunchDarklySecretKey();
11+
if (cachedClient) {
12+
return cachedClient;
13+
}
1014

15+
const ldSecretKey = getLaunchDarklySecretKey();
1116
if (!ldSecretKey) {
1217
getLogger().error(`No LaunchDarkly secret available.`);
1318
return null;
@@ -23,7 +28,8 @@ export async function getLDClient(): Promise<LDClient | null> {
2328
};
2429
const client = init(ldSecretKey, options);
2530
await client.waitForInitialization();
26-
return client;
31+
cachedClient = client;
32+
return cachedClient;
2733
}
2834

2935
export async function getFeatureFlag<T>(

src/usecases/handle-figma-file-update-event-use-case.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { v4 as uuidv4 } from 'uuid';
22

33
import { handleFigmaFileUpdateEventUseCase } from './handle-figma-file-update-event-use-case';
44

5-
import * as launchDarkly from '../config/launch_darkly';
65
import { FigmaTeamAuthStatus } from '../domain/entities';
76
import {
87
generateAssociatedFigmaDesign,
@@ -28,11 +27,6 @@ import type { FigmaWebhookInfo } from '../web/routes/figma';
2827

2928
describe('handleFigmaFileUpdateEventUseCase', () => {
3029
describe('file webhook', () => {
31-
beforeEach(() => {
32-
jest.spyOn(launchDarkly, 'getLDClient').mockResolvedValue(null);
33-
jest.spyOn(launchDarkly, 'getFeatureFlag').mockResolvedValue(true);
34-
});
35-
3630
it('should handle file webhook events', async () => {
3731
const connectInstallation = generateConnectInstallation();
3832
jest

src/usecases/handle-figma-file-update-event-use-case.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { uniqueWith } from '../common/array-utils';
2-
import { getFeatureFlag, getLDClient } from '../config/launch_darkly';
32
import type { ConnectUserInfo } from '../domain/entities';
43
import { FigmaTeamAuthStatus } from '../domain/entities';
54
import { getLogger } from '../infrastructure';
@@ -60,16 +59,6 @@ export const handleFigmaFileUpdateEventUseCase = {
6059
}
6160

6261
case 'file': {
63-
const ldClient = await getLDClient();
64-
const useFileWebhooks = await getFeatureFlag(
65-
ldClient,
66-
'ext_figma_for_jira_use_file_webhooks',
67-
false,
68-
);
69-
if (!useFileWebhooks) {
70-
return;
71-
}
72-
7362
const figmaFileWebhook = webhookInfo.figmaFileWebhook;
7463
return await syncDesignsToJira(
7564
fileKey,

src/usecases/on-design-associated-with-issue-use-case.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { InvalidInputUseCaseResultError } from './errors';
55
import type { OnDesignAssociatedWithIssueUseCaseParams } from './on-design-associated-with-issue-use-case';
66
import { onDesignAssociatedWithIssueUseCaseParams } from './on-design-associated-with-issue-use-case';
77

8-
import * as launch_darkly from '../config/launch_darkly';
98
import {
109
type AssociatedFigmaDesign,
1110
type FigmaFileWebhook,
@@ -61,11 +60,6 @@ const generateWebhookV2 = (
6160
});
6261

6362
describe('onDesignAssociatedWithIssueUseCase', () => {
64-
beforeEach(() => {
65-
// set getFeatureFlag to return true for all feature flags
66-
jest.spyOn(launch_darkly, 'getFeatureFlag').mockResolvedValue(true);
67-
});
68-
6963
it('should store associated Design data, handle backward integration, and create file webhooks', async () => {
7064
const figmaDesignId = generateFigmaDesignIdentifier();
7165
const params = generateOnDesignAssociatedWithIssueUseCaseParams({

src/usecases/on-design-associated-with-issue-use-case.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { v4 as uuidv4 } from 'uuid';
22

33
import { InvalidInputUseCaseResultError } from './errors';
44

5-
import { getFeatureFlag, getLDClient } from '../config/launch_darkly';
65
import type { ConnectInstallation } from '../domain/entities';
76
import {
87
FigmaDesignIdentifier,
@@ -97,17 +96,6 @@ async function maybeCreateFigmaFileWebhooks(
9796
atlassianUserId: string,
9897
connectInstallationId: string,
9998
): Promise<void> {
100-
const ldClient = await getLDClient();
101-
const useFileWebhooks = await getFeatureFlag(
102-
ldClient,
103-
'ext_figma_for_jira_use_file_webhooks',
104-
false,
105-
);
106-
107-
if (!useFileWebhooks) {
108-
return;
109-
}
110-
11199
const existingWebhook =
112100
await figmaFileWebhookRepository.findByFileKeyAndEventTypeAndConnectInstallationId(
113101
fileKey,

src/usecases/on-design-disassociated-from-issue-use-case.test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { InvalidInputUseCaseResultError } from './errors';
44
import type { OnDesignDisassociatedFromIssueUseCaseParams } from './on-design-disassociated-from-issue-use-case';
55
import { onDesignDisassociatedFromIssueUseCase } from './on-design-disassociated-from-issue-use-case';
66

7-
import * as launchDarkly from '../config/launch_darkly';
87
import {
98
type AssociatedFigmaDesign,
109
FigmaFileWebhookEventType,
@@ -44,9 +43,6 @@ const generateOnDesignDisassociatedWithIssueUseCaseParams = ({
4443

4544
describe('onDesignDisassociatedWithIssueUseCase', () => {
4645
it('should delete stored associated Design data and handle backward integration', async () => {
47-
jest.spyOn(launchDarkly, 'getLDClient').mockResolvedValue(null);
48-
jest.spyOn(launchDarkly, 'getFeatureFlag').mockResolvedValue(true);
49-
5046
const figmaDesignId = generateFigmaDesignIdentifier();
5147
const params = generateOnDesignDisassociatedWithIssueUseCaseParams({
5248
designId: figmaDesignId.toAtlassianDesignId(),
@@ -126,9 +122,6 @@ describe('onDesignDisassociatedWithIssueUseCase', () => {
126122
});
127123

128124
it('should not delete file webhooks more files rely on them', async () => {
129-
jest.spyOn(launchDarkly, 'getLDClient').mockResolvedValue(null);
130-
jest.spyOn(launchDarkly, 'getFeatureFlag').mockResolvedValue(true);
131-
132125
const figmaDesignId = generateFigmaDesignIdentifier();
133126
const params = generateOnDesignDisassociatedWithIssueUseCaseParams({
134127
designId: figmaDesignId.toAtlassianDesignId(),

src/usecases/on-design-disassociated-from-issue-use-case.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { InvalidInputUseCaseResultError } from './errors';
22

3-
import { getFeatureFlag, getLDClient } from '../config/launch_darkly';
43
import type { ConnectInstallation } from '../domain/entities';
54
import { FigmaDesignIdentifier } from '../domain/entities';
65
import { figmaBackwardIntegrationServiceV2 } from '../infrastructure';
@@ -65,17 +64,6 @@ async function maybeTryDeleteFigmaFileWebhooks(
6564
figmaDesignId: FigmaDesignIdentifier,
6665
connectInstallationId: string,
6766
): Promise<void> {
68-
const ldClient = await getLDClient();
69-
const useFileWebhooks = await getFeatureFlag(
70-
ldClient,
71-
'ext_figma_for_jira_use_file_webhooks',
72-
false,
73-
);
74-
75-
if (!useFileWebhooks) {
76-
return;
77-
}
78-
7967
const associatedDesigns =
8068
await associatedFigmaDesignRepository.findManyByFileKeyAndConnectInstallationId(
8169
figmaDesignId.fileKey,

src/web/routes/entities-v2/integration.test.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313

1414
import app from '../../../app';
1515
import { buildAppUrl, getConfig } from '../../../config';
16-
import * as launchDarkly from '../../../config/launch_darkly';
1716
import {
1817
buildJiraIssueUrl,
1918
FigmaFileWebhookEventType,
@@ -353,6 +352,12 @@ describe('/entities', () => {
353352
nodeId: '0:0',
354353
}),
355354
});
355+
mockFigmaCreateWebhookEndpoint({
356+
baseUrl: getConfig().figma.apiBaseUrl,
357+
});
358+
mockFigmaCreateWebhookEndpoint({
359+
baseUrl: getConfig().figma.apiBaseUrl,
360+
});
356361

357362
await request(app)
358363
.put(buildAppUrl('entities/onEntityAssociated').pathname)
@@ -374,10 +379,7 @@ describe('/entities', () => {
374379
.expect(HttpStatusCode.Ok);
375380
});
376381

377-
it('should create Figma webhooks for the file when the feature flag is enabled', async () => {
378-
jest.spyOn(launchDarkly, 'getLDClient').mockResolvedValue(null);
379-
jest.spyOn(launchDarkly, 'getFeatureFlag').mockResolvedValue(true);
380-
382+
it('should create Figma webhooks for the file', async () => {
381383
const connectInstallation = await connectInstallationRepository.upsert(
382384
generateConnectInstallationCreateParams(),
383385
);
@@ -524,6 +526,12 @@ describe('/entities', () => {
524526
issueId,
525527
status: HttpStatusCode.NotFound,
526528
});
529+
mockFigmaCreateWebhookEndpoint({
530+
baseUrl: getConfig().figma.apiBaseUrl,
531+
});
532+
mockFigmaCreateWebhookEndpoint({
533+
baseUrl: getConfig().figma.apiBaseUrl,
534+
});
527535

528536
await request(app)
529537
.put(buildAppUrl('entities/onEntityAssociated').pathname)
@@ -682,6 +690,12 @@ describe('/entities', () => {
682690
}),
683691
status: HttpStatusCode.Forbidden,
684692
});
693+
mockFigmaCreateWebhookEndpoint({
694+
baseUrl: getConfig().figma.apiBaseUrl,
695+
});
696+
mockFigmaCreateWebhookEndpoint({
697+
baseUrl: getConfig().figma.apiBaseUrl,
698+
});
685699

686700
await request(app)
687701
.put(buildAppUrl('entities/onEntityAssociated').pathname)
@@ -758,6 +772,12 @@ describe('/entities', () => {
758772
nodeId: '0:0',
759773
}),
760774
});
775+
mockFigmaCreateWebhookEndpoint({
776+
baseUrl: getConfig().figma.apiBaseUrl,
777+
});
778+
mockFigmaCreateWebhookEndpoint({
779+
baseUrl: getConfig().figma.apiBaseUrl,
780+
});
761781

762782
await request(app)
763783
.put(buildAppUrl('entities/onEntityAssociated').pathname)

src/web/routes/figma/integration.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import app from '../../../app';
1313
import { isNotNullOrUndefined } from '../../../common/predicates';
1414
import { isString } from '../../../common/string-utils';
1515
import { buildAppUrl, getConfig } from '../../../config';
16-
import * as launchDarkly from '../../../config/launch_darkly';
1716
import type {
1817
AtlassianDesign,
1918
ConnectInstallation,
@@ -603,11 +602,6 @@ describe('/figma', () => {
603602
});
604603

605604
describe('/webhook/file', () => {
606-
beforeEach(() => {
607-
jest.spyOn(launchDarkly, 'getLDClient').mockResolvedValue(null);
608-
jest.spyOn(launchDarkly, 'getFeatureFlag').mockResolvedValue(true);
609-
});
610-
611605
describe('FILE_UPDATE event', () => {
612606
const currentDate = new Date();
613607
let connectInstallation: ConnectInstallation;

0 commit comments

Comments
 (0)