From a06d1f6ff9fb3a1bbff7146aea029c2ec31cf5ff Mon Sep 17 00:00:00 2001 From: danoswaltCL <97542869+danoswaltCL@users.noreply.github.com> Date: Wed, 10 Apr 2024 12:03:43 -0400 Subject: [PATCH] fix client lib build errors --- .../src/app/app-config.ts | 1 - .../general-test-for-version5.service.ts | 14 +- .../mock-mathstream-browser.service.ts | 304 ------------------ .../app/services/mock-client-app.service.ts | 4 - clientlibs/libTesters/shared/constants.ts | 1 - 5 files changed, 6 insertions(+), 318 deletions(-) delete mode 100644 clientlibs/libTesters/client-lib-tester-frontend/src/app/mockFrontendClientAppComponents/mock-mathstream-browser.service.ts diff --git a/clientlibs/libTesters/client-lib-tester-frontend/src/app/app-config.ts b/clientlibs/libTesters/client-lib-tester-frontend/src/app/app-config.ts index 37cd50e02e..abe62a3c8d 100644 --- a/clientlibs/libTesters/client-lib-tester-frontend/src/app/app-config.ts +++ b/clientlibs/libTesters/client-lib-tester-frontend/src/app/app-config.ts @@ -48,5 +48,4 @@ export const availableFrontendMockApps = [ MOCK_APP_NAMES.GENERAL_TS_FRONTEND_4_1, MOCK_APP_NAMES.GENERAL_TS_FRONTEND_5_0, MOCK_APP_NAMES.PORTAL_APP, - MOCK_APP_NAMES.MATHSTREAM_AdaptiveSegmentSwapExperiment, ]; diff --git a/clientlibs/libTesters/client-lib-tester-frontend/src/app/mockFrontendClientAppComponents/general-test-for-version5.service.ts b/clientlibs/libTesters/client-lib-tester-frontend/src/app/mockFrontendClientAppComponents/general-test-for-version5.service.ts index 5978c43b00..3acb931238 100644 --- a/clientlibs/libTesters/client-lib-tester-frontend/src/app/mockFrontendClientAppComponents/general-test-for-version5.service.ts +++ b/clientlibs/libTesters/client-lib-tester-frontend/src/app/mockFrontendClientAppComponents/general-test-for-version5.service.ts @@ -16,6 +16,7 @@ import { AbstractMockAppService } from './abstract-mock-app.service'; import { MOCK_APP_NAMES } from '../../../../shared/constants'; import { HttpClient } from '@angular/common/http'; import { lastValueFrom } from 'rxjs'; +import { IUserAliases } from '../../../../../../types/src/Experiment/interfaces'; @Injectable({ providedIn: 'root', @@ -382,8 +383,7 @@ export class GeneralTestForVersion5Service extends AbstractMockAppService { console.error('User info is missing userAliases:', user); } try { - const useraliasesResponse: UpGradeClientInterfaces.IExperimentUserAliases[] = - await this.upgradeClient.setAltUserIds(user.userAliases); + const useraliasesResponse: IUserAliases = await this.upgradeClient.setAltUserIds(user.userAliases); console.log({ useraliasesResponse }); } catch (err) { console.error(err); @@ -398,9 +398,8 @@ export class GeneralTestForVersion5Service extends AbstractMockAppService { console.error('User info is missing groups:', user); } try { - const groupMembershipResponse: UpGradeClientInterfaces.IExperimentUser = await this.upgradeClient.setGroupMembership( - user.groups - ); + const groupMembershipResponse: UpGradeClientInterfaces.IExperimentUser = + await this.upgradeClient.setGroupMembership(user.groups); console.log({ groupMembershipResponse }); } catch (err) { console.error(err); @@ -415,9 +414,8 @@ export class GeneralTestForVersion5Service extends AbstractMockAppService { console.error('User info is missing working groups:', user); } try { - const workingGroupMembershipResponse: UpGradeClientInterfaces.IExperimentUser = await this.upgradeClient.setWorkingGroup( - user.workingGroup - ); + const workingGroupMembershipResponse: UpGradeClientInterfaces.IExperimentUser = + await this.upgradeClient.setWorkingGroup(user.workingGroup); console.log({ workingGroupMembershipResponse }); } catch (err) { console.error(err); diff --git a/clientlibs/libTesters/client-lib-tester-frontend/src/app/mockFrontendClientAppComponents/mock-mathstream-browser.service.ts b/clientlibs/libTesters/client-lib-tester-frontend/src/app/mockFrontendClientAppComponents/mock-mathstream-browser.service.ts deleted file mode 100644 index 6592f296fa..0000000000 --- a/clientlibs/libTesters/client-lib-tester-frontend/src/app/mockFrontendClientAppComponents/mock-mathstream-browser.service.ts +++ /dev/null @@ -1,304 +0,0 @@ -import { Injectable } from '@angular/core'; -import { ClientLibraryService } from '../services/client-library.service'; -import { EventBusService } from '../services/event-bus.service'; -import { ClientAppHook, CodeLanguage, MockAppType, MockClientAppInterfaceModel } from '../../../../shared/models'; - -// There's probably a clever way to do this, but getting the right types automatically is tricky - -import UpgradeClient, { IExperimentAssignment } from 'upgrade_client_1_1_8/dist/browser'; - -import { AbstractMockAppService } from './abstract-mock-app.service'; -import { MOCK_APP_NAMES } from '../../../../shared/constants'; - -export const QUESTION_SWAP_EXPERIMENT = { - CONTEXT: 'mathstream', - SITE: 'DisplayQuestion', - CONTROL: 'learnosity-item-control', -}; - -export interface ActiveExperiment { - originalActivityId: string; - selectedActivityId: string; - conditionCode: string; -} - -@Injectable({ - providedIn: 'root', -}) -export class MockMathstreamBrowserService extends AbstractMockAppService { - public override upgradeClient!: UpgradeClient; - // public upgradeClient: any; - - /******************* required metadata to describe the mock app and its callable hooks ********************/ - public NAME = MOCK_APP_NAMES.MATHSTREAM_AdaptiveSegmentSwapExperiment; - public DESCRIPTION = 'Test for Version 1 library code in Mathstream'; - public TYPE: MockAppType = 'frontend'; - public LANGUAGE: CodeLanguage = 'ts'; - public SITES = { - DisplayQuestion: 'DisplayQuestion', - }; - public TARGETS = { - TARGET_1: 'AR-VST-0150-6.NS.8-1_SP_008', - TARGET_2: 'AR-VST-0150-6.NS.8-1_SP_004', - TARGET_3: 'AR-VST-0150-6.NS.8-1_SP_014', - }; - public GROUPS = ['schoolId', 'classId', 'instructorId']; - public CONTEXT = 'mathstream'; - public HOOKNAMES = { - init: 'init', - getExperimentalQuestionIfExists: 'GET CONDITION IF EXISTS', - markExperimentBeginning: 'MARK', - logExperimentConcluding: 'LOG', - }; - public DECISION_POINTS = [ - { site: this.SITES.DisplayQuestion, target: this.TARGETS.TARGET_1 }, - { site: this.SITES.DisplayQuestion, target: this.TARGETS.TARGET_2 }, - { site: this.SITES.DisplayQuestion, target: this.TARGETS.TARGET_3 }, - ]; - - // this is specific to the mocked component - private activeExperiments: ActiveExperiment[] = []; - - constructor(public override clientLibraryService: ClientLibraryService, public override eventBus: EventBusService) { - super(MOCK_APP_NAMES.MATHSTREAM_AdaptiveSegmentSwapExperiment, eventBus, clientLibraryService); - } - - /******************* "getAppInterfaceModel" required to give tester app a model to construct an interface to use this 'app' ********************/ - - public getAppInterfaceModel(): MockClientAppInterfaceModel { - return { - name: this.NAME, - description: this.DESCRIPTION, - type: this.TYPE, - language: this.LANGUAGE, - hooks: [ - { - name: this.HOOKNAMES.init, - description: 'REQUIRED TO RUN FIRST. runs init(), needs userId string as payload.', - }, - { - name: this.HOOKNAMES.getExperimentalQuestionIfExists, - description: 'runs getExperimentalQuestionIfExists(), needs activityId string as payload', - }, - { - name: this.HOOKNAMES.markExperimentBeginning, - description: 'mark experiment point with given activityId payload', - }, - { - name: this.HOOKNAMES.logExperimentConcluding, - description: 'log metric for percent correct for given question', - }, - ], - decisionPoints: this.DECISION_POINTS, - groups: this.GROUPS, - buttons: [ - { - hookName: this.HOOKNAMES.init, - label: 'init (Run before other hooks!)', - }, - { - hookName: this.HOOKNAMES.getExperimentalQuestionIfExists, - label: `Get assignment for: ${this.TARGETS.TARGET_1}`, - props: { - activityId: this.TARGETS.TARGET_1, - }, - }, - { - hookName: this.HOOKNAMES.getExperimentalQuestionIfExists, - label: `Get assignment for: ${this.TARGETS.TARGET_2}`, - props: { - activityId: this.TARGETS.TARGET_2, - }, - }, - { - hookName: this.HOOKNAMES.getExperimentalQuestionIfExists, - label: `Get assignment for: ${this.TARGETS.TARGET_3}`, - props: { - activityId: this.TARGETS.TARGET_3, - }, - }, - { - hookName: this.HOOKNAMES.getExperimentalQuestionIfExists, - label: `Get assignment for: no activity id`, - props: { - activityId: 'no activity id', - }, - }, - { - hookName: this.HOOKNAMES.markExperimentBeginning, - label: `Mark condition for: ${this.TARGETS.TARGET_1}`, - props: { - activityId: this.TARGETS.TARGET_1, - }, - }, - { - hookName: this.HOOKNAMES.markExperimentBeginning, - label: `Mark condition for: ${this.TARGETS.TARGET_2}`, - props: { - activityId: this.TARGETS.TARGET_2, - }, - }, - { - hookName: this.HOOKNAMES.markExperimentBeginning, - label: `Mark condition for: ${this.TARGETS.TARGET_3}`, - props: { - activityId: this.TARGETS.TARGET_3, - }, - }, - { - hookName: this.HOOKNAMES.markExperimentBeginning, - label: `Mark condition for: no activity id`, - props: { - activityId: 'no activity id', - }, - }, - { - hookName: this.HOOKNAMES.logExperimentConcluding, - label: `Log question answered correctly`, - props: { - questionAnsweredCorrectly: true, - }, - }, - { - hookName: this.HOOKNAMES.logExperimentConcluding, - label: `Log question answered incorrectly`, - props: { - questionAnsweredCorrectly: false, - }, - }, - ], - }; - } - - /******************* "routeHook" required to route requests from tester-app to simulated client code snippets ********************/ - public routeHook(hookEvent: ClientAppHook) { - const { name, user } = hookEvent; - if (name === '') return; - - if (!user || !user.id) { - throw new Error('No user found in hookEvent'); - } - - if (name === this.HOOKNAMES.init && user?.id) { - this.init(user.id); - } else if (name === this.HOOKNAMES.getExperimentalQuestionIfExists && hookEvent?.payload?.activityId) { - this.getExperimentalQuestionIfExists(hookEvent.payload.activityId); - } else if (name === this.HOOKNAMES.markExperimentBeginning && hookEvent?.payload?.activityId) { - this.markExperimentBeginning(hookEvent.payload.activityId); - } else if ( - name === this.HOOKNAMES.logExperimentConcluding && - typeof hookEvent?.payload?.questionAnsweredCorrectly === 'boolean' - ) { - this.logExperimentConcluding(hookEvent.payload.questionAnsweredCorrectly); - } else { - throw new Error(`No hook found for hookName: ${name}`); - } - } - - /******************* simulated client app code ****************************************************/ - - async init(userId: string) { - this.upgradeClient = this.constructUpgradeClient(userId); - const initResponse = await this.upgradeClient.init(); - console.log('upgradeClient', this.upgradeClient); - console.log({ initResponse }); - } - - async getExperimentalQuestionIfExists(activityId: string): Promise { - let selectedActivityId = activityId; - try { - const experimentAssignment = await this.getExperimentAssignment(activityId); - - console.log('[getExperimentalQuestionIfExists] assignment:', experimentAssignment); - selectedActivityId = this.determineActivityToUse(experimentAssignment, activityId); - } catch (err) { - console.log('upgradeClient error', err); - } - - console.log('[getExperimentalQuestionIfExists] selectedActivityId:', selectedActivityId); - - return selectedActivityId; - } - - private determineActivityToUse( - experimentAssignment: IExperimentAssignment | null, - originalActivityId: string - ): string { - let selectedActivityId = originalActivityId; - if (!experimentAssignment) return selectedActivityId; - const conditionCode = experimentAssignment.assignedCondition.conditionCode; - - if (conditionCode === QUESTION_SWAP_EXPERIMENT.CONTROL) { - selectedActivityId = originalActivityId; - } else if (conditionCode !== QUESTION_SWAP_EXPERIMENT.CONTROL) { - selectedActivityId = conditionCode; - } - this.addActiveExperimentToCache({ - originalActivityId: originalActivityId, - selectedActivityId: selectedActivityId, - conditionCode: conditionCode, - }); - console.log('Active Experiments', this.activeExperiments); - return selectedActivityId; - } - - private addActiveExperimentToCache(activeExperiment: ActiveExperiment): void { - this.activeExperiments.push(activeExperiment); - } - - async markExperimentBeginning(activityId: string): Promise { - try { - const foundExperiment = this.popActiveExperiment(activityId); - console.log({ foundExperiment }); - if (!foundExperiment) return; - const markResponse = await this.upgradeClient.markExperimentPoint( - QUESTION_SWAP_EXPERIMENT.SITE, - foundExperiment?.conditionCode, - foundExperiment?.originalActivityId - ); - - console.log({ markResponse }); - } catch (err) { - console.log('upgradeClient error', err); - } - } - - async logExperimentConcluding(questionAnsweredCorrectly: boolean): Promise { - try { - let percentCorrect = 0; - if (questionAnsweredCorrectly) percentCorrect = 100; - const logResponse = await this.upgradeClient.log([ - { - timestamp: new Date().toISOString(), - metrics: { - attributes: { - percentCorrect: percentCorrect, - }, - groupedMetrics: [] as any[], - }, - }, - ]); - - console.log({ logResponse }); - } catch (err) { - console.log('upgradeClient error', err); - } - } - - private popActiveExperiment(activityId: string): ActiveExperiment | undefined { - const foundIndex = this.activeExperiments.findIndex((x) => x.selectedActivityId === activityId); - if (foundIndex < 0) return undefined; - const foundExperiment = this.activeExperiments[foundIndex]; - this.activeExperiments.splice(foundIndex, 1); - return foundExperiment; - } - - private async getExperimentAssignment(activityId: string): Promise { - const upgradeCondition = await this.upgradeClient.getExperimentCondition( - QUESTION_SWAP_EXPERIMENT.CONTEXT, - QUESTION_SWAP_EXPERIMENT.SITE, - activityId - ); - return upgradeCondition; - } -} diff --git a/clientlibs/libTesters/client-lib-tester-frontend/src/app/services/mock-client-app.service.ts b/clientlibs/libTesters/client-lib-tester-frontend/src/app/services/mock-client-app.service.ts index 7e18782422..c56cc279ea 100644 --- a/clientlibs/libTesters/client-lib-tester-frontend/src/app/services/mock-client-app.service.ts +++ b/clientlibs/libTesters/client-lib-tester-frontend/src/app/services/mock-client-app.service.ts @@ -11,7 +11,6 @@ import { ClientLibraryService } from './client-library.service'; import { GeneralTestForVersion41Service } from '../mockFrontendClientAppComponents/general-test-for-version4-1.service'; import { GeneralTestForVersion1Service } from '../mockFrontendClientAppComponents/general-test-for-version1.service'; import { GeneralTestForVersion5Service } from '../mockFrontendClientAppComponents/general-test-for-version5.service'; -import { MockMathstreamBrowserService } from '../mockFrontendClientAppComponents/mock-mathstream-browser.service'; @Injectable({ providedIn: 'root', @@ -26,7 +25,6 @@ export class MockClientAppService { public generalTest_1_1: GeneralTestForVersion1Service, public generalTest_4_1: GeneralTestForVersion41Service, public generalTest_5: GeneralTestForVersion5Service, - // public mathstream_AdaptiveSegmentSwapExperiment: MockMathstreamBrowserService, public dataFetchService: DataFetchService, public eventBus: EventBusService, public clientLibraryService: ClientLibraryService @@ -37,8 +35,6 @@ export class MockClientAppService { [MOCK_APP_NAMES.GENERAL_TS_FRONTEND_1_1]: generalTest_1_1.getAppInterfaceModel(), [MOCK_APP_NAMES.GENERAL_TS_FRONTEND_4_1]: generalTest_4_1.getAppInterfaceModel(), [MOCK_APP_NAMES.GENERAL_TS_FRONTEND_5_0]: generalTest_5.getAppInterfaceModel(), - [MOCK_APP_NAMES.MATHSTREAM_AdaptiveSegmentSwapExperiment]: - mathstream_AdaptiveSegmentSwapExperiment.getAppInterfaceModel(), }; } diff --git a/clientlibs/libTesters/shared/constants.ts b/clientlibs/libTesters/shared/constants.ts index 556118c67c..74b83785ff 100644 --- a/clientlibs/libTesters/shared/constants.ts +++ b/clientlibs/libTesters/shared/constants.ts @@ -8,5 +8,4 @@ export const MOCK_APP_NAMES = { GENERAL_TS_FRONTEND_5_0: 'General TS Browser v5.0', BDAY_APP: 'Birthday App Browser', PORTAL_APP: 'Mock Portal', - MATHSTREAM_AdaptiveSegmentSwapExperiment: 'Mathstream: AdaptiveSegmentSwapExperiment', };