diff --git a/packages/profile-sync-controller/src/controllers/user-storage/__fixtures__/mockResponses.ts b/packages/profile-sync-controller/src/controllers/user-storage/__fixtures__/mockResponses.ts index 94e9229215..e66ee062b5 100644 --- a/packages/profile-sync-controller/src/controllers/user-storage/__fixtures__/mockResponses.ts +++ b/packages/profile-sync-controller/src/controllers/user-storage/__fixtures__/mockResponses.ts @@ -33,43 +33,70 @@ export const getMockUserStorageEndpoint = ( )}`; }; -export const createMockGetStorageResponse = async ( +/** + * Creates a mock GET user-storage response + * @param data - data to encrypt + * @returns a realistic GET Response Body + */ +export async function createMockGetStorageResponse( data?: string, -): Promise => ({ - HashedKey: 'HASHED_KEY', - Data: await MOCK_ENCRYPTED_STORAGE_DATA(data), -}); +): Promise { + return { + HashedKey: 'HASHED_KEY', + Data: await MOCK_ENCRYPTED_STORAGE_DATA(data), + }; +} -export const createMockAllFeatureEntriesResponse = async ( +/** + * Creates a mock GET ALL user-storage response + * @param dataArr - array of data to encrypt + * @returns a realistic GET ALL Response Body + */ +export async function createMockAllFeatureEntriesResponse( dataArr: string[] = [MOCK_STORAGE_DATA], -): Promise => - Promise.all( - dataArr.map(async (d) => ({ - HashedKey: 'HASHED_KEY', - Data: await MOCK_ENCRYPTED_STORAGE_DATA(d), - })), +): Promise { + return await Promise.all( + dataArr.map(async function (d) { + const encryptedData = await MOCK_ENCRYPTED_STORAGE_DATA(d); + return { + HashedKey: 'HASHED_KEY', + Data: encryptedData, + }; + }), ); +} -export const getMockUserStorageGetResponse = async ( +/** + * Creates a mock user-storage api GET request + * @param path - path of the GET Url + * @returns mock GET API request. Can be used by e2e or unit mock servers + */ +export async function getMockUserStorageGetResponse( path: UserStoragePathWithFeatureAndKey = 'notifications.notification_settings', -) => { +) { return { url: getMockUserStorageEndpoint(path), requestMethod: 'GET', response: await createMockGetStorageResponse(), } satisfies MockResponse; -}; +} -export const getMockUserStorageAllFeatureEntriesResponse = async ( +/** + * Creates a mock user-storage api GET ALL request + * @param path - path of the GET url + * @param dataArr - data to encrypt + * @returns mock GET ALL API request. Can be used by e2e or unit mock servers + */ +export async function getMockUserStorageAllFeatureEntriesResponse( path: UserStoragePathWithFeatureOnly = 'notifications', dataArr?: string[], -) => { +) { return { url: getMockUserStorageEndpoint(path), requestMethod: 'GET', response: await createMockAllFeatureEntriesResponse(dataArr), } satisfies MockResponse; -}; +} export const getMockUserStoragePutResponse = ( path: UserStoragePathWithFeatureAndKey = 'notifications.notification_settings',