Skip to content

Commit

Permalink
Merge pull request #254 from jwplayer/fix/inp-watch-history
Browse files Browse the repository at this point in the history
fix: Watch history update on new media
  • Loading branch information
kiremitrov123 authored Mar 14, 2023
2 parents 88f88a9 + 1865489 commit 9cd393f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,4 @@
"flat": "^5.0.1",
"json5": "^2.2.2"
}
}
}
12 changes: 5 additions & 7 deletions src/services/inplayer.account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,18 +272,16 @@ export const subscribeToNotifications = async (uuid: string = '', onMessage: (pa
export const updatePersonalShelves: UpdatePersonalShelves = async (payload) => {
const { favorites, history } = payload.externalData;
const externalData = await getCustomerExternalData();
const currentWatchHistoryIds = externalData?.history?.map((e) => e.mediaid);
const currentFavoriteIds = externalData?.favorites?.map((e) => e.mediaid);
const payloadFavoriteIds = favorites?.map((e) => e.mediaid);

try {
history.forEach(async (history) => {
if (externalData?.history?.length) {
externalData?.history?.forEach(async (historyStore) => {
if (historyStore.mediaid === history.mediaid && historyStore.progress !== history.progress) {
await InPlayer.Account.updateWatchHistory(history.mediaid, history.progress);
}
});
} else {
if (
!currentWatchHistoryIds?.includes(history.mediaid) ||
externalData?.history?.some((e) => e.mediaid == history.mediaid && e.progress != history.progress)
) {
await InPlayer.Account.updateWatchHistory(history.mediaid, history.progress);
}
});
Expand Down
1 change: 1 addition & 0 deletions test-e2e/codecept.desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ exports.config = {
url: 'http://localhost:8080',
show: !!process.env.SHOW,
channel: 'chrome',
locale: 'en-US',
},
},
include: {
Expand Down
8 changes: 4 additions & 4 deletions test-e2e/tests/payments/subscription_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LoginContext } from '#utils/password_utils';
import constants, { longTimeout, normalTimeout } from '#utils/constants';
import { overrideIP, goToCheckout, formatPrice, finishAndCheckSubscription, cancelPlan, renewPlan, addDays } from '#utils/payments';
import { overrideIP, goToCheckout, formatPrice, finishAndCheckSubscription, cancelPlan, renewPlan, addDays, addYear } from '#utils/payments';
import { testConfigs } from '#test/constants';

let paidLoginContext: LoginContext;
Expand Down Expand Up @@ -159,15 +159,15 @@ Scenario('I can finish my subscription', async ({ I }) => {
// @ts-expect-error
I.switchTo(null); // Exit the iframe context back to the main document

await finishAndCheckSubscription(I, addDays(today, 365), today);
await finishAndCheckSubscription(I, addYear(today), today);

I.seeAll(cardInfo);
});

Scenario('I can cancel my subscription', async ({ I }) => {
paidLoginContext = await I.registerOrLogin(paidLoginContext);

cancelPlan(I, addDays(today, 365));
cancelPlan(I, addYear(today));

// Still see payment info
I.seeAll(cardInfo);
Expand All @@ -176,5 +176,5 @@ Scenario('I can cancel my subscription', async ({ I }) => {
Scenario('I can renew my subscription', async ({ I }) => {
paidLoginContext = await I.registerOrLogin(paidLoginContext);

renewPlan(I, addDays(today, 365));
renewPlan(I, addYear(today));
});
2 changes: 1 addition & 1 deletion test-e2e/utils/payments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function addYear(date: Date) {
}

export function formatDate(date: Date) {
return date.toLocaleDateString('en-US');
return date.toLocaleDateString();
}

export async function finishAndCheckSubscription(I: CodeceptJS.I, billingDate: Date, today: Date) {
Expand Down

0 comments on commit 9cd393f

Please sign in to comment.