Skip to content

Commit

Permalink
another checkpoint, backend builds. tests need to wait for PR
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswk committed Dec 12, 2023
1 parent aa7f5be commit 7241ef9
Show file tree
Hide file tree
Showing 80 changed files with 954 additions and 214 deletions.
7 changes: 2 additions & 5 deletions src/lib/addons/slack-app.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {
IEvent,
FEATURE_ENVIRONMENT_ENABLED,
SYSTEM_USER_ID,
} from '../types/events';
import { IEvent, FEATURE_ENVIRONMENT_ENABLED } from '../types/events';
import SlackAppAddon from './slack-app';
import { ChatPostMessageArguments, ErrorCode } from '@slack/web-api';
import { SYSTEM_USER_ID } from '../types';

const slackApiCalls: ChatPostMessageArguments[] = [];

Expand Down
2 changes: 1 addition & 1 deletion src/lib/addons/slack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import {
FEATURE_ARCHIVED,
FEATURE_ENVIRONMENT_DISABLED,
IEvent,
SYSTEM_USER_ID,
} from '../types/events';
import { Logger } from '../logger';

import SlackAddon from './slack';

import noLogger from '../../test/fixtures/no-logger';
import { SYSTEM_USER_ID } from '../types';

let fetchRetryCalls: any[] = [];

Expand Down
2 changes: 1 addition & 1 deletion src/lib/addons/teams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
FEATURE_CREATED,
FEATURE_ENVIRONMENT_DISABLED,
IEvent,
SYSTEM_USER_ID,
} from '../types/events';

import TeamsAddon from './teams';

import noLogger from '../../test/fixtures/no-logger';
import { SYSTEM_USER_ID } from '../types';

let fetchRetryCalls: any[];

Expand Down
3 changes: 2 additions & 1 deletion src/lib/addons/webhook.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Logger } from '../logger';

import { FEATURE_CREATED, IEvent, SYSTEM_USER_ID } from '../types/events';
import { FEATURE_CREATED, IEvent } from '../types/events';

import WebhookAddon from './webhook';

import noLogger from '../../test/fixtures/no-logger';
import { SYSTEM_USER_ID } from '../types';

let fetchRetryCalls: any[] = [];

Expand Down
1 change: 1 addition & 0 deletions src/lib/db/event-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ class EventStore implements IEventStore {
return {
type: e.type,
created_by: e.createdBy ?? 'admin',
created_by_user_id: e.createdByUserId,
data: Array.isArray(e.data) ? JSON.stringify(e.data) : e.data,
pre_data: Array.isArray(e.preData)
? JSON.stringify(e.preData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ export default class ExportImportService
value: tag.tagValue,
},
extractUsernameFromUser(user),
user.id,
);
}
}
Expand All @@ -406,6 +407,7 @@ export default class ExportImportService
stickiness: contextField.stickiness,
},
extractUsernameFromUser(user),
user.id,
),
),
);
Expand All @@ -419,6 +421,7 @@ export default class ExportImportService
? this.tagTypeService.createTagType(
tagType,
extractUsernameFromUser(user),
user.id,
)
: Promise.resolve();
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const createToggle = async (
tags: string[] = [],
projectId: string = 'default',
username: string = 'test',
userId: number = -9999,
) => {
await app.services.featureToggleServiceV2.createFeatureToggle(
projectId,
Expand Down Expand Up @@ -89,6 +90,7 @@ const createToggle = async (
value: tag,
},
username,
userId,
);
}),
);
Expand Down
6 changes: 6 additions & 0 deletions src/lib/features/feature-toggle/feature-toggle-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ export default class ProjectFeaturesController extends Controller {
description: req.body.description || undefined,
},
userName,
req.user.id,
);

this.openApiService.respondWithValidation(
Expand Down Expand Up @@ -734,6 +735,7 @@ export default class ProjectFeaturesController extends Controller {
},
userName,
featureName,
req.user.id,
);

this.openApiService.respondWithValidation(
Expand All @@ -759,6 +761,7 @@ export default class ProjectFeaturesController extends Controller {
featureName,
extractUsername(req),
req.body,
req.user.id,
);
this.openApiService.respondWithValidation(
200,
Expand Down Expand Up @@ -801,6 +804,7 @@ export default class ProjectFeaturesController extends Controller {
stale,
userName,
projectId,
req.user.id,
);
res.status(202).end();
}
Expand Down Expand Up @@ -1109,6 +1113,7 @@ export default class ProjectFeaturesController extends Controller {
value,
{ environment, projectId, featureName },
userName,
req.user.id,
);
res.status(200).json(updatedStrategy);
}
Expand All @@ -1124,6 +1129,7 @@ export default class ProjectFeaturesController extends Controller {
tags.addedTags,
tags.removedTags,
userName,
req.user.id,
);
res.status(200).end();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ class FeatureController extends Controller {
featureName,
req.body,
userName,
req.user.id,
);
res.status(201).header('location', `${featureName}/tags`).json(tag);
}
Expand All @@ -279,13 +280,23 @@ class FeatureController extends Controller {

await Promise.all(
addedTags.map((addedTag) =>
this.tagService.addTag(featureName, addedTag, userName),
this.tagService.addTag(
featureName,
addedTag,
userName,
req.user.id,
),
),
);

await Promise.all(
removedTags.map((removedTag) =>
this.tagService.removeTag(featureName, removedTag, userName),
this.tagService.removeTag(
featureName,
removedTag,
userName,
req.user.id,
),
),
);

Expand All @@ -300,7 +311,12 @@ class FeatureController extends Controller {
): Promise<void> {
const { featureName, type, value } = req.params;
const userName = extractUsername(req);
await this.tagService.removeTag(featureName, { type, value }, userName);
await this.tagService.removeTag(
featureName,
{ type, value },
userName,
req.user.id,
);
res.status(200).end();
}

Expand Down Expand Up @@ -328,6 +344,7 @@ class FeatureController extends Controller {
project,
validatedToggle,
userName,
req.user.id,
true,
);
const strategies = await Promise.all(
Expand All @@ -351,7 +368,13 @@ class FeatureController extends Controller {
enabled,
userName,
);
await this.service.saveVariants(name, project, variants, userName);
await this.service.saveVariants(
name,
project,
variants,
userName,
req.user.id,
);

res.status(201).json({
...createdFeature,
Expand All @@ -376,6 +399,7 @@ class FeatureController extends Controller {
value,
userName,
featureName,
req.user.id,
);

await this.service.removeAllStrategiesForEnv(featureName);
Expand All @@ -385,30 +409,37 @@ class FeatureController extends Controller {
updatedFeature.strategies.map(async (s) =>
this.service.createStrategy(
s,
{ projectId, featureName, environment: DEFAULT_ENV },
{
projectId: projectId!!,
featureName,
environment: DEFAULT_ENV,
},
userName,
req.user,
),
),
);
}
await this.service.updateEnabled(
projectId,
projectId!!,
featureName,
DEFAULT_ENV,
updatedFeature.enabled,
userName,
req.user,
);
await this.service.saveVariants(
featureName,
projectId,
projectId!!,
value.variants || [],
userName,
req.user.id,
);

const feature = await this.service.storeFeatureUpdatedEventLegacy(
featureName,
userName,
req.user.id,
);

res.status(200).json(feature);
Expand All @@ -432,6 +463,7 @@ class FeatureController extends Controller {
await this.service.storeFeatureUpdatedEventLegacy(
featureName,
userName,
req.user.id,
);
res.status(200).json(feature);
}
Expand All @@ -450,6 +482,7 @@ class FeatureController extends Controller {
await this.service.storeFeatureUpdatedEventLegacy(
featureName,
userName,
req.user.id,
);
res.json(feature);
}
Expand All @@ -468,22 +501,33 @@ class FeatureController extends Controller {
await this.service.storeFeatureUpdatedEventLegacy(
featureName,
userName,
req.user.id,
);
res.json(feature);
}

async staleOn(req: IAuthRequest, res: Response): Promise<void> {
const { featureName } = req.params;
const userName = extractUsername(req);
await this.service.updateStale(featureName, true, userName);
await this.service.updateStale(
featureName,
true,
userName,
req.user.id,
);
const feature = await this.service.getFeatureToggleLegacy(featureName);
res.json(feature);
}

async staleOff(req: IAuthRequest, res: Response): Promise<void> {
const { featureName } = req.params;
const userName = extractUsername(req);
await this.service.updateStale(featureName, false, userName);
await this.service.updateStale(
featureName,
false,
userName,
req.user.id,
);
const feature = await this.service.getFeatureToggleLegacy(featureName);
res.json(feature);
}
Expand Down
Loading

0 comments on commit 7241ef9

Please sign in to comment.