Skip to content

Commit

Permalink
checkpoint for adding createdByUserId to all events
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswk committed Dec 12, 2023
1 parent 1c95029 commit aa7f5be
Show file tree
Hide file tree
Showing 18 changed files with 355 additions and 58 deletions.
7 changes: 7 additions & 0 deletions src/lib/addons/datadog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ test('Should call datadog webhook', async () => {
createdAt: new Date(),
type: FEATURE_CREATED,
createdBy: '[email protected]',
createdByUserId: -1337,
featureName: 'some-toggle',
data: {
name: 'some-toggle',
Expand Down Expand Up @@ -74,6 +75,7 @@ test('Should call datadog webhook for archived toggle', async () => {
createdAt: new Date(),
type: FEATURE_ARCHIVED,
createdBy: '[email protected]',
createdByUserId: -1337,
featureName: 'some-toggle',
data: {
name: 'some-toggle',
Expand Down Expand Up @@ -102,6 +104,7 @@ test('Should call datadog webhook for archived toggle with project info', async
type: FEATURE_ARCHIVED,
createdBy: '[email protected]',
featureName: 'some-toggle',
createdByUserId: -1337,
project: 'some-project',
data: {
name: 'some-toggle',
Expand Down Expand Up @@ -129,6 +132,7 @@ test('Should call datadog webhook for toggled environment', async () => {
createdAt: new Date(),
type: FEATURE_ENVIRONMENT_DISABLED,
createdBy: '[email protected]',
createdByUserId: -1337,
environment: 'development',
project: 'default',
featureName: 'some-toggle',
Expand Down Expand Up @@ -160,6 +164,7 @@ test('Should include customHeaders in headers when calling service', async () =>
type: FEATURE_ENVIRONMENT_DISABLED,
createdBy: '[email protected]',
environment: 'development',
createdByUserId: -1337,
project: 'default',
featureName: 'some-toggle',
data: {
Expand Down Expand Up @@ -190,6 +195,7 @@ test('Should not include source_type_name when included in the config', async ()
createdAt: new Date(),
type: FEATURE_ENVIRONMENT_DISABLED,
createdBy: '[email protected]',
createdByUserId: -1337,
environment: 'development',
project: 'default',
featureName: 'some-toggle',
Expand Down Expand Up @@ -224,6 +230,7 @@ test('Should call datadog webhook with JSON when template set', async () => {
createdAt: new Date(),
type: FEATURE_CREATED,
createdBy: '[email protected]',
createdByUserId: -1337,
featureName: 'some-toggle',
data: {
name: 'some-toggle',
Expand Down
17 changes: 17 additions & 0 deletions src/lib/addons/feature-event-formatter-md.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
FEATURE_STRATEGY_REMOVE,
FEATURE_STRATEGY_UPDATE,
IEvent,
SYSTEM_USER_ID,
} from '../types';

import { FeatureEventFormatterMd } from './feature-event-formatter-md';
Expand Down Expand Up @@ -34,6 +35,7 @@ const testCases: [string, IEvent][] = [
id: 920,
type: FEATURE_STRATEGY_UPDATE,
createdBy: '[email protected]',
createdByUserId: SYSTEM_USER_ID,
createdAt: new Date('2022-06-01T10:03:11.549Z'),
data: {
id: '3f4bf713-696c-43a4-8ce7-d6c607108858',
Expand Down Expand Up @@ -67,6 +69,7 @@ const testCases: [string, IEvent][] = [
id: 920,
type: FEATURE_STRATEGY_UPDATE,
createdBy: '[email protected]',
createdByUserId: SYSTEM_USER_ID,
createdAt: new Date('2022-06-01T10:03:11.549Z'),
data: {
id: '3f4bf713-696c-43a4-8ce7-d6c607108858',
Expand Down Expand Up @@ -100,6 +103,7 @@ const testCases: [string, IEvent][] = [
id: 920,
type: FEATURE_STRATEGY_UPDATE,
createdBy: '[email protected]',
createdByUserId: SYSTEM_USER_ID,
createdAt: new Date('2022-06-01T10:03:11.549Z'),
data: {
id: '3f4bf713-696c-43a4-8ce7-d6c607108858',
Expand Down Expand Up @@ -133,6 +137,7 @@ const testCases: [string, IEvent][] = [
id: 920,
type: FEATURE_STRATEGY_UPDATE,
createdBy: '[email protected]',
createdByUserId: SYSTEM_USER_ID,
createdAt: new Date('2022-06-01T10:03:11.549Z'),
data: {
id: '3f4bf713-696c-43a4-8ce7-d6c607108858',
Expand Down Expand Up @@ -174,6 +179,7 @@ const testCases: [string, IEvent][] = [
id: 920,
type: FEATURE_STRATEGY_UPDATE,
createdBy: '[email protected]',
createdByUserId: SYSTEM_USER_ID,
createdAt: new Date('2022-06-01T10:03:11.549Z'),
data: {
id: '3f4bf713-696c-43a4-8ce7-d6c607108858',
Expand Down Expand Up @@ -207,6 +213,7 @@ const testCases: [string, IEvent][] = [
id: 919,
type: FEATURE_STRATEGY_ADD,
createdBy: '[email protected]',
createdByUserId: SYSTEM_USER_ID,
createdAt: new Date('2022-06-01T10:03:08.290Z'),
data: {
id: '3f4bf713-696c-43a4-8ce7-d6c607108858',
Expand All @@ -231,6 +238,7 @@ const testCases: [string, IEvent][] = [
id: 918,
type: FEATURE_STRATEGY_REMOVE,
createdBy: '[email protected]',
createdByUserId: SYSTEM_USER_ID,
createdAt: new Date('2022-06-01T10:03:00.229Z'),
data: null,
preData: {
Expand All @@ -253,6 +261,7 @@ const testCases: [string, IEvent][] = [
id: 39,
type: FEATURE_STRATEGY_UPDATE,
createdBy: 'admin',
createdByUserId: SYSTEM_USER_ID,
createdAt: new Date('2023-02-20T20:23:28.791Z'),
data: {
id: 'f2d34aac-52ec-49d2-82d3-08d710e89eaa',
Expand Down Expand Up @@ -310,6 +319,7 @@ const testCases: [string, IEvent][] = [
type: FEATURE_STRATEGY_UPDATE,
createdBy: 'admin',
createdAt: new Date('2023-02-20T20:23:28.791Z'),
createdByUserId: SYSTEM_USER_ID,
data: {
id: 'f2d34aac-52ec-49d2-82d3-08d710e89eaa',
name: 'default',
Expand Down Expand Up @@ -346,6 +356,7 @@ const testCases: [string, IEvent][] = [
id: 920,
type: FEATURE_STRATEGY_UPDATE,
createdBy: '[email protected]',
createdByUserId: SYSTEM_USER_ID,
createdAt: new Date('2022-06-01T10:03:11.549Z'),
data: {
name: 'userWithId',
Expand Down Expand Up @@ -385,6 +396,7 @@ const testCases: [string, IEvent][] = [
id: 920,
type: FEATURE_STRATEGY_UPDATE,
createdBy: '[email protected]',
createdByUserId: SYSTEM_USER_ID,
createdAt: new Date('2022-06-01T10:03:11.549Z'),
data: {
name: 'remoteAddress',
Expand Down Expand Up @@ -421,6 +433,7 @@ const testCases: [string, IEvent][] = [
type: FEATURE_STRATEGY_UPDATE,
createdBy: '[email protected]',
createdAt: new Date('2022-06-01T10:03:11.549Z'),
createdByUserId: SYSTEM_USER_ID,
data: {
name: 'applicationHostname',
constraints: [
Expand Down Expand Up @@ -456,6 +469,7 @@ const testCases: [string, IEvent][] = [
type: FEATURE_STRATEGY_UPDATE,
createdBy: '[email protected]',
createdAt: new Date('2022-06-01T10:03:11.549Z'),
createdByUserId: SYSTEM_USER_ID,
data: {
name: 'newStrategy',
constraints: [
Expand Down Expand Up @@ -491,6 +505,7 @@ const testCases: [string, IEvent][] = [
type: CHANGE_REQUEST_SCHEDULED,
createdBy: '[email protected]',
createdAt: new Date('2022-06-01T10:03:11.549Z'),
createdByUserId: SYSTEM_USER_ID,
data: {
changeRequestId: 1,
},
Expand All @@ -508,6 +523,7 @@ const testCases: [string, IEvent][] = [
type: CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
createdBy: '[email protected]',
createdAt: new Date('2022-06-01T10:03:11.549Z'),
createdByUserId: SYSTEM_USER_ID,
data: {
changeRequestId: 1,
},
Expand All @@ -524,6 +540,7 @@ const testCases: [string, IEvent][] = [
id: 920,
type: CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
createdBy: '[email protected]',
createdByUserId: SYSTEM_USER_ID,
createdAt: new Date('2022-06-01T10:03:11.549Z'),
data: {
changeRequestId: 1,
Expand Down
7 changes: 6 additions & 1 deletion src/lib/addons/slack-app.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { IEvent, FEATURE_ENVIRONMENT_ENABLED } from '../types/events';
import {
IEvent,
FEATURE_ENVIRONMENT_ENABLED,
SYSTEM_USER_ID,
} from '../types/events';
import SlackAppAddon from './slack-app';
import { ChatPostMessageArguments, ErrorCode } from '@slack/web-api';

Expand Down Expand Up @@ -44,6 +48,7 @@ describe('SlackAppAddon', () => {
id: 1,
createdAt: new Date(),
type: FEATURE_ENVIRONMENT_ENABLED,
createdByUserId: SYSTEM_USER_ID,
createdBy: '[email protected]',
project: 'default',
featureName: 'some-toggle',
Expand Down
9 changes: 9 additions & 0 deletions src/lib/addons/slack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
FEATURE_ARCHIVED,
FEATURE_ENVIRONMENT_DISABLED,
IEvent,
SYSTEM_USER_ID,
} from '../types/events';
import { Logger } from '../logger';

Expand Down Expand Up @@ -44,6 +45,7 @@ test('Should call slack webhook', async () => {
id: 1,
createdAt: new Date(),
type: FEATURE_CREATED,
createdByUserId: SYSTEM_USER_ID,
createdBy: '[email protected]',
project: 'default',
featureName: 'some-toggle',
Expand Down Expand Up @@ -74,6 +76,7 @@ test('Should call slack webhook for archived toggle', async () => {
const event: IEvent = {
id: 2,
createdAt: new Date(),
createdByUserId: SYSTEM_USER_ID,
type: FEATURE_ARCHIVED,
featureName: 'some-toggle',
createdBy: '[email protected]',
Expand Down Expand Up @@ -101,6 +104,7 @@ test('Should call slack webhook for archived toggle with project info', async ()
const event: IEvent = {
id: 2,
createdAt: new Date(),
createdByUserId: SYSTEM_USER_ID,
type: FEATURE_ARCHIVED,
featureName: 'some-toggle',
project: 'some-project',
Expand Down Expand Up @@ -129,6 +133,7 @@ test(`Should call webhook for toggled environment`, async () => {
const event: IEvent = {
id: 2,
createdAt: new Date(),
createdByUserId: SYSTEM_USER_ID,
type: FEATURE_ENVIRONMENT_DISABLED,
createdBy: '[email protected]',
environment: 'development',
Expand Down Expand Up @@ -159,6 +164,7 @@ test('Should use default channel', async () => {
const event: IEvent = {
id: 3,
createdAt: new Date(),
createdByUserId: SYSTEM_USER_ID,
type: FEATURE_CREATED,
createdBy: '[email protected]',
featureName: 'some-toggle',
Expand Down Expand Up @@ -189,6 +195,7 @@ test('Should override default channel with data from tag', async () => {
const event: IEvent = {
id: 4,
createdAt: new Date(),
createdByUserId: SYSTEM_USER_ID,
type: FEATURE_CREATED,
createdBy: '[email protected]',
featureName: 'some-toggle',
Expand Down Expand Up @@ -225,6 +232,7 @@ test('Should post to all channels in tags', async () => {
const event: IEvent = {
id: 5,
createdAt: new Date(),
createdByUserId: SYSTEM_USER_ID,
type: FEATURE_CREATED,
createdBy: '[email protected]',
featureName: 'some-toggle',
Expand Down Expand Up @@ -269,6 +277,7 @@ test('Should include custom headers from parameters in call to service', async (
id: 2,
createdAt: new Date(),
type: FEATURE_ENVIRONMENT_DISABLED,
createdByUserId: SYSTEM_USER_ID,
createdBy: '[email protected]',
environment: 'development',
project: 'default',
Expand Down
6 changes: 6 additions & 0 deletions src/lib/addons/teams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
FEATURE_CREATED,
FEATURE_ENVIRONMENT_DISABLED,
IEvent,
SYSTEM_USER_ID,
} from '../types/events';

import TeamsAddon from './teams';
Expand Down Expand Up @@ -45,6 +46,7 @@ test('Should call teams webhook', async () => {
id: 1,
createdAt: new Date(),
type: FEATURE_CREATED,
createdByUserId: SYSTEM_USER_ID,
createdBy: '[email protected]',
featureName: 'some-toggle',
data: {
Expand Down Expand Up @@ -72,6 +74,7 @@ test('Should call teams webhook for archived toggle', async () => {
const event: IEvent = {
id: 1,
createdAt: new Date(),
createdByUserId: SYSTEM_USER_ID,
type: FEATURE_ARCHIVED,
createdBy: '[email protected]',
featureName: 'some-toggle',
Expand All @@ -98,6 +101,7 @@ test('Should call teams webhook for archived toggle with project info', async ()
const event: IEvent = {
id: 1,
createdAt: new Date(),
createdByUserId: SYSTEM_USER_ID,
type: FEATURE_ARCHIVED,
createdBy: '[email protected]',
featureName: 'some-toggle',
Expand Down Expand Up @@ -125,6 +129,7 @@ test(`Should call teams webhook for toggled environment`, async () => {
const event: IEvent = {
id: 2,
createdAt: new Date(),
createdByUserId: SYSTEM_USER_ID,
type: FEATURE_ENVIRONMENT_DISABLED,
createdBy: '[email protected]',
environment: 'development',
Expand Down Expand Up @@ -154,6 +159,7 @@ test('Should include custom headers in call to teams', async () => {
const event: IEvent = {
id: 2,
createdAt: new Date(),
createdByUserId: SYSTEM_USER_ID,
type: FEATURE_ENVIRONMENT_DISABLED,
createdBy: '[email protected]',
environment: 'development',
Expand Down
6 changes: 5 additions & 1 deletion src/lib/addons/webhook.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Logger } from '../logger';

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

import WebhookAddon from './webhook';

Expand Down Expand Up @@ -36,6 +36,7 @@ test('Should handle event without "bodyTemplate"', () => {
const event: IEvent = {
id: 1,
createdAt: new Date(),
createdByUserId: SYSTEM_USER_ID,
type: FEATURE_CREATED,
createdBy: '[email protected]',
featureName: 'some-toggle',
Expand All @@ -61,6 +62,7 @@ test('Should format event with "bodyTemplate"', () => {
const event: IEvent = {
id: 1,
createdAt: new Date(),
createdByUserId: SYSTEM_USER_ID,
type: FEATURE_CREATED,
createdBy: '[email protected]',
featureName: 'some-toggle',
Expand Down Expand Up @@ -90,6 +92,7 @@ test('Should format event with "authorization"', () => {
const event: IEvent = {
id: 1,
createdAt: new Date(),
createdByUserId: SYSTEM_USER_ID,
type: FEATURE_CREATED,
createdBy: '[email protected]',
featureName: 'some-toggle',
Expand Down Expand Up @@ -120,6 +123,7 @@ test('Should handle custom headers', async () => {
const event: IEvent = {
id: 1,
createdAt: new Date(),
createdByUserId: SYSTEM_USER_ID,
type: FEATURE_CREATED,
createdBy: '[email protected]',
featureName: 'some-toggle',
Expand Down
2 changes: 2 additions & 0 deletions src/lib/db/event-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export interface IEventTable {
type: string;
created_by: string;
created_at: Date;
created_by_user_id: number;
data?: any;
pre_data?: any;
feature_name?: string;
Expand Down Expand Up @@ -364,6 +365,7 @@ class EventStore implements IEventStore {
type: row.type as IEventType,
createdBy: row.created_by,
createdAt: row.created_at,
createdByUserId: row.created_by_user_id,
data: row.data,
preData: row.pre_data,
tags: row.tags || [],
Expand Down
Loading

0 comments on commit aa7f5be

Please sign in to comment.