Skip to content

Commit

Permalink
MC-1646: replace ScheduleItemSource enum with ActivitySource enum (#265)
Browse files Browse the repository at this point in the history
* (chore)MC-1646: replace ScheduleItemSource enum with ActivitySource enum
  • Loading branch information
katerinachinnappan authored Feb 4, 2025
1 parent 38d0cd5 commit 9ffb241
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 100 deletions.
4 changes: 2 additions & 2 deletions lambdas/corpus-scheduler-lambda/src/testHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
CorpusLanguage,
CreateApprovedCorpusItemApiInput,
CuratedStatus,
ScheduledItemSource,
ActivitySource,
ScheduledSurfacesEnum,
Topics,
UrlMetadata,
Expand Down Expand Up @@ -150,7 +150,7 @@ export const getCreateApprovedCorpusItemApiOutput = (
imageUrl: 'https://fake-image-url.com',
topic: Topics.SELF_IMPROVEMENT,
source: CorpusItemSource.ML,
scheduledSource: ScheduledItemSource.ML,
scheduledSource: ActivitySource.ML,
isCollection: false,
isSyndicated: false,
isTimeSensitive: false,
Expand Down
6 changes: 3 additions & 3 deletions lambdas/corpus-scheduler-lambda/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
CreateApprovedCorpusItemApiInput,
CreateScheduledItemInput,
CuratedCorpusApiErrorCodes,
ScheduledItemSource,
ActivitySource,
UrlMetadata,
} from 'content-common';
import {
Expand Down Expand Up @@ -265,7 +265,7 @@ export const mapScheduledCandidateInputToCreateApprovedCorpusItemApiInput =
imageUrl: imageUrl,
topic: topic,
source: source, // source = Metaflow
scheduledSource: source as unknown as ScheduledItemSource.ML,
scheduledSource: source as unknown as ActivitySource.ML,
isCollection: itemMetadata.isCollection as boolean, // source = Parser
isSyndicated: itemMetadata.isSyndicated as boolean, // source = Parser
isTimeSensitive: false,
Expand Down Expand Up @@ -311,7 +311,7 @@ export const createCreateScheduledItemInput = async (
candidate.scheduled_corpus_item.scheduled_surface_guid,
scheduledDate: candidate.scheduled_corpus_item.scheduled_date,
source: candidate.scheduled_corpus_item
.source as unknown as ScheduledItemSource,
.source as unknown as ActivitySource,
};
// assert itemToSchedule against CreateScheduledItemInput before sending to mutation
assert<CreateScheduledItemInput>(itemToSchedule);
Expand Down
9 changes: 2 additions & 7 deletions packages/content-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ export enum ActivitySource {
ML = 'ML', // created by ML
}

export enum ScheduledItemSource {
MANUAL = 'MANUAL', // manually entered through the curation admin tool
ML = 'ML', // created by ML
}

export enum ActionScreen {
PROSPECTING = 'PROSPECTING',
SCHEDULE = 'SCHEDULE',
Expand Down Expand Up @@ -107,7 +102,7 @@ export type CreateApprovedCorpusItemApiInput = ApprovedItemRequiredInput & {
// Note that all three must be present to schedule the item.
scheduledDate?: string;
scheduledSurfaceGuid?: string;
scheduledSource?: ScheduledItemSource;
scheduledSource?: ActivitySource;
// This is an optional property that may or may not be present at the time
// a corpus item is saved in the datastore
datePublished?: string;
Expand All @@ -120,7 +115,7 @@ export type CreateScheduledItemInput = {
approvedItemExternalId: string;
scheduledSurfaceGuid: string;
scheduledDate: string;
source: ScheduledItemSource;
source: ActivitySource;
};


Expand Down
24 changes: 5 additions & 19 deletions servers/curated-corpus-api/schema-admin.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,6 @@ enum CorpusItemSource {
ML
}

"""
The source of the Scheduled item
"""
enum ScheduledItemSource {
"""
Manually entered through the curation admin tool
"""
MANUAL
"""
Created by ML
"""
ML
}

"""
Indicates where in the Curation Tools UI the action took place
"""
Expand Down Expand Up @@ -485,7 +471,7 @@ type ScheduledCorpusItem {
"""
Source of the Scheduled Item. Could be one of: MANUAL or ML
"""
source: ScheduledItemSource!
source: ActivitySource!
}

"""
Expand Down Expand Up @@ -826,7 +812,7 @@ input CreateApprovedCorpusItemInput {
"""
Optionally, specify the source of the Scheduled Item. Could be one of: MANUAL or ML
"""
scheduledSource: ScheduledItemSource
scheduledSource: ActivitySource
"""
The UI screen where the approved corpus item is being created from.
"""
Expand Down Expand Up @@ -915,7 +901,7 @@ input ImportApprovedCorpusItemInput {
This field was added after this import mutation was created. We may need to expand the enum value list if this mutation is used in the future.
"""
scheduledSource: ScheduledItemSource!
scheduledSource: ActivitySource!
}

"""
Expand Down Expand Up @@ -1070,7 +1056,7 @@ input CreateScheduledCorpusItemInput {
"""
Source of the Scheduled Item. Could be one of: MANUAL or ML
"""
source: ScheduledItemSource!
source: ActivitySource!
"""
A comma-separated list of reasons for manually scheduling an item. Helps ML improve models for sets of scheduled items.
"""
Expand Down Expand Up @@ -1101,7 +1087,7 @@ input RescheduleScheduledCorpusItemInput {
"""
Source of the Scheduled Item. Could be one of: MANUAL or ML
"""
source: ScheduledItemSource!
source: ActivitySource!
"""
The UI screen where the scheduled corpus item is being resceduled from.
Can only be from the schedule screen.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
CreateApprovedCorpusItemApiInput,
CorpusItemSource,
CuratedStatus,
ScheduledItemSource,
ActivitySource,
Topics,
} from 'content-common';

Expand Down Expand Up @@ -256,7 +256,7 @@ describe('mutations: ApprovedItem (createApprovedCorpusItem)', () => {
// extra inputs - all three must be set to create a scheduled item
input.scheduledDate = '2100-01-01';
input.scheduledSurfaceGuid = 'NEW_TAB_EN_US';
input.scheduledSource = ScheduledItemSource.ML;
input.scheduledSource = ActivitySource.ML;

const result = await request(app)
.post(graphQLUrl)
Expand Down Expand Up @@ -310,7 +310,7 @@ describe('mutations: ApprovedItem (createApprovedCorpusItem)', () => {
);
expect(
emitScheduledCorpusItemEventArgs.scheduledCorpusItem.generated_by,
).toEqual(ScheduledItemSource.ML);
).toEqual(ActivitySource.ML);

// 3- Events have the right entities passed to it.
expect(
Expand All @@ -329,7 +329,7 @@ describe('mutations: ApprovedItem (createApprovedCorpusItem)', () => {
// extra inputs - all three must be set to create a scheduled item
input.scheduledDate = '2100-01-01';
input.scheduledSurfaceGuid = 'NEW_TAB_EN_US';
input.scheduledSource = ScheduledItemSource.ML;
input.scheduledSource = ActivitySource.ML;

const pastApprovedItem = await createApprovedItemHelper(db, {
url: `${input.url}/old-article`,
Expand Down Expand Up @@ -451,7 +451,7 @@ describe('mutations: ApprovedItem (createApprovedCorpusItem)', () => {
// extra inputs
input.scheduledDate = '2100-01-01';
input.scheduledSurfaceGuid = 'RECSAPI';
input.scheduledSource = ScheduledItemSource.ML;
input.scheduledSource = ActivitySource.ML;

const result = await request(app)
.post(graphQLUrl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import request from 'supertest';
import { ApolloServer } from '@apollo/server';
import { PrismaClient } from '.prisma/client';

import { ActionScreen, ScheduledItemSource } from 'content-common';
import { ActionScreen, ActivitySource } from 'content-common';

import { client } from '../../../../database/client';
import {
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('mutations: ScheduledItem (createScheduledItem)', () => {
approvedItemExternalId: approvedItem.externalId,
scheduledSurfaceGuid: 'RECSAPI',
scheduledDate: '2100-01-01',
source: ScheduledItemSource.MANUAL,
source: ActivitySource.MANUAL,
};

const result = await request(app)
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('mutations: ScheduledItem (createScheduledItem)', () => {
approvedItemExternalId: 'not-a-valid-id-at-all',
scheduledSurfaceGuid: 'NEW_TAB_EN_US',
scheduledDate: '2100-01-01',
source: ScheduledItemSource.MANUAL,
source: ActivitySource.MANUAL,
reasons: `${ManualScheduleReason.EVERGREEN},${ManualScheduleReason.PUBLISHER_DIVERSITY}`,
reasonComment: 'i scheduled this because i thought it would be nice',
};
Expand Down Expand Up @@ -160,7 +160,7 @@ describe('mutations: ScheduledItem (createScheduledItem)', () => {
approvedItemExternalId: item.externalId,
scheduledSurfaceGuid: existingScheduledEntry.scheduledSurfaceGuid,
scheduledDate,
source: ScheduledItemSource.MANUAL,
source: ActivitySource.MANUAL,
reasons: `${ManualScheduleReason.EVERGREEN},${ManualScheduleReason.PUBLISHER_DIVERSITY}`,
reasonComment: 'i scheduled this because i thought it would be nice',
};
Expand Down Expand Up @@ -205,7 +205,7 @@ describe('mutations: ScheduledItem (createScheduledItem)', () => {
approvedItemExternalId: approvedItem.externalId,
scheduledSurfaceGuid: 'NEW_TAB_EN_US',
scheduledDate: '2100-01-01',
source: ScheduledItemSource.MANUAL,
source: ActivitySource.MANUAL,
reasons: `${ManualScheduleReason.EVERGREEN},${ManualScheduleReason.PUBLISHER_DIVERSITY}`,
reasonComment: 'i scheduled this because i thought it would be nice',
actionScreen: ActionScreen.SCHEDULE,
Expand Down Expand Up @@ -251,7 +251,7 @@ describe('mutations: ScheduledItem (createScheduledItem)', () => {
approvedItemExternalId: approvedItem.externalId,
scheduledSurfaceGuid: 'NEW_TAB_EN_US',
scheduledDate: '2100-01-01',
source: ScheduledItemSource.MANUAL,
source: ActivitySource.MANUAL,
reasons: `${ManualScheduleReason.EVERGREEN},${ManualScheduleReason.PUBLISHER_DIVERSITY}`,
reasonComment: 'i scheduled this because i thought it would be nice',
};
Expand All @@ -271,7 +271,7 @@ describe('mutations: ScheduledItem (createScheduledItem)', () => {
expect(scheduledItem.createdAt).not.toBeNull();
expect(scheduledItem.updatedAt).not.toBeNull();
expect(scheduledItem.createdBy).toEqual(headers.username);
expect(scheduledItem.source).toEqual(ScheduledItemSource.MANUAL);
expect(scheduledItem.source).toEqual(ActivitySource.MANUAL);

// Expect these to match the input values
expect(new Date(scheduledItem.scheduledDate)).toStrictEqual(
Expand Down Expand Up @@ -352,7 +352,7 @@ describe('mutations: ScheduledItem (createScheduledItem)', () => {
approvedItemExternalId: newApprovedItem.externalId,
scheduledSurfaceGuid: 'NEW_TAB_EN_US',
scheduledDate: toUtcDateString(new Date()),
source: ScheduledItemSource.ML,
source: ActivitySource.ML,
};

await request(app)
Expand Down Expand Up @@ -380,7 +380,7 @@ describe('mutations: ScheduledItem (createScheduledItem)', () => {
approvedItemExternalId: approvedItem.externalId,
scheduledSurfaceGuid: 'NEW_TAB_EN_US',
scheduledDate: toUtcDateString(new Date()),
source: ScheduledItemSource.ML,
source: ActivitySource.ML,
};

await request(app)
Expand Down Expand Up @@ -411,7 +411,7 @@ describe('mutations: ScheduledItem (createScheduledItem)', () => {
approvedItemExternalId: approvedItem.externalId,
scheduledSurfaceGuid: 'NEW_TAB_EN_US',
scheduledDate: toUtcDateString(new Date()),
source: ScheduledItemSource.ML,
source: ActivitySource.ML,
};

// Run the mutation
Expand Down Expand Up @@ -448,7 +448,7 @@ describe('mutations: ScheduledItem (createScheduledItem)', () => {
approvedItemExternalId: approvedItem.externalId,
scheduledSurfaceGuid: 'NEW_TAB_EN_US',
scheduledDate: '2100-01-01',
source: ScheduledItemSource.MANUAL,
source: ActivitySource.MANUAL,
reasons: `${ManualScheduleReason.EVERGREEN},${ManualScheduleReason.PUBLISHER_DIVERSITY}`,
reasonComment: 'i scheduled this because i thought it would be nice',
};
Expand Down Expand Up @@ -485,7 +485,7 @@ describe('mutations: ScheduledItem (createScheduledItem)', () => {
approvedItemExternalId: approvedItem.externalId,
scheduledSurfaceGuid: 'NEW_TAB_EN_US',
scheduledDate: '2100-01-01',
source: ScheduledItemSource.MANUAL,
source: ActivitySource.MANUAL,
reasons: `${ManualScheduleReason.EVERGREEN},${ManualScheduleReason.PUBLISHER_DIVERSITY}`,
reasonComment: 'i scheduled this because i thought it would be nice',
};
Expand Down Expand Up @@ -522,7 +522,7 @@ describe('mutations: ScheduledItem (createScheduledItem)', () => {
approvedItemExternalId: approvedItem.externalId,
scheduledSurfaceGuid: 'NEW_TAB_EN_US',
scheduledDate: '2100-01-01',
source: ScheduledItemSource.MANUAL,
source: ActivitySource.MANUAL,
};

const result = await request(app)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
CuratedCorpusApiErrorCodes,
parseReasonsCsv,
sanitizeText,
ScheduledItemSource,
ActivitySource,
} from 'content-common';

import config from '../../../../config';
Expand Down Expand Up @@ -88,7 +88,7 @@ export async function deleteScheduledItem(
scheduledCorpusItem: {
...scheduledItem,
action_screen: actionScreen,
generated_by: scheduledItem.source as ScheduledItemSource,
generated_by: scheduledItem.source as ActivitySource,
// analytics requires a unique id per action on an existing scheduled
// item. we create an ephemeral unique id for them here using the same
// version of UUID that prisma uses. this service has no requirement to
Expand Down
Loading

0 comments on commit 9ffb241

Please sign in to comment.