Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug #5537/newsletter functionality #5601

Closed
wants to merge 16 commits into from

Conversation

Baroshem
Copy link
Contributor

@Baroshem Baroshem commented Mar 2, 2021

Related Issues

closes #5537

Short Description and Why It's Useful

This pull request implements functionality for updating newsletter sections. For now it's just a mock (similarly to user billing), so after page reload checked checkboxes won't be checked. However, if the user navigates the pages/sections, the checkboxes will remain checked.

Screenshots of Visual Changes before/after (if There Are Any)

Which Environment This Relates To

Check your case. In case of any doubts please read about Release Cycle

  • Test version (https://test.storefrontcloud.io) - this is a new feature or improvement for Vue Storefront. I've created branch from develop branch and want to merge it back to develop
  • RC version (https://next.storefrontcloud.io) - this is a stabilisation fix for Release Candidate of Vue Storefront. I've created branch from release branch and want to merge it back to release
  • Stable version (https://demo.storefrontcloud.io) - this is an important fix for current stable version. I've created branch from hotfix or master branch and want to merge it back to hotfix

Upgrade Notes and Changelog

  • No upgrade steps required (100% backward compatibility and no breaking changes)
  • I've updated the Upgrade notes and Changelog on how to port existing Vue Storefront sites with this new feature
  • (Next only) I've followed this instruction and I've created a .js file with information about my Pull Request

IMPORTANT NOTICE

  • Remember to update CHANGELOG.md with description of your change

Contribution and Currently Important Rules Acceptance

@Baroshem Baroshem self-assigned this Mar 2, 2021
@CLAassistant
Copy link

CLAassistant commented Mar 2, 2021

CLA assistant check
All committers have signed the CLA.

@coveralls
Copy link

coveralls commented Mar 2, 2021

Pull Request Test Coverage Report for Build 613559196

  • 31 of 31 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+5.3%) to 86.36%

Totals Coverage Status
Change from base Build 613485104: 5.3%
Covered Lines: 846
Relevant Lines: 965

💛 - Coveralls

@Baroshem Baroshem mentioned this pull request Mar 2, 2021
4 tasks
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2021

💙 vsf-next-demo successfully deployed at https://90607d712e9e1aadc630117f7848c5f85287a340.vsf-next-demo.preview.storefrontcloud.io

@coveralls
Copy link

Pull Request Test Coverage Report for Build 613559196

  • 0 of 42 (100.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-15.7%) to 65.314%

Totals Coverage Status
Change from base Build 613485104: -15.7%
Covered Lines: 322
Relevant Lines: 395

💛 - Coveralls

@coveralls
Copy link

coveralls commented Mar 2, 2021

Pull Request Test Coverage Report for Build 613559196

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 42 of 42 (100.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.3%) to 81.328%

Totals Coverage Status
Change from base Build 613485104: 0.3%
Covered Lines: 1548
Relevant Lines: 1770

💛 - Coveralls

@Baroshem Baroshem changed the title [WIP] Bug #5537/newsletter and profile Bug #5537/newsletter functionality Mar 2, 2021
@Baroshem Baroshem requested a review from filrak March 2, 2021 10:02
@filrak
Copy link
Collaborator

filrak commented Mar 2, 2021

It was not intended to add a new composable with #5537. I'm closing for now - likely useNewsletter topic will come back

@filrak filrak closed this Mar 2, 2021
}
};

const updateNewsletterData = async (newsletter): Promise<NewsletterSections> => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateNewsletterData name is redundant because it's already is part of useNewsletter. I suggest naming it just update to match load method.

export interface UseNewsletterFactoryParams extends FactoryParams {
updateNewsletterData: (
context: Context,
params: NewsletterSections) => Promise<NewsletterSections>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

) => Promise<NewsletterSections>; should go to the next line

description: 'create update newsletter sections functionality',
link: 'https://github.com/vuestorefront/vue-storefront/issues/5537',
isBreaking: true,
breakingChanges: [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useNewsletter composable is not BC, because it's totally new composable. However, changes in MyNewsletter.vue that require a new component that uses new composable is BC :)

{
   {
      module: 'core / commercetools',
      before: '',
      after: 'Added newsletter functionality',
      comment: 'Added \'useNewsletter\' composable and \'components/MyAccount/NewsletterForm.vue\' component, modified \'pages/MyAccount/MyNewsletter.vue\' component'
    }
}

Comment on lines +157 to +161
export interface NewsletterSections {
woman: boolean,
man: boolean,
kids: boolean,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't hardcode Newsletter options.

Comment on lines +163 to +169
export interface UseNewsletter {
newsletter: ComputedProperty<NewsletterSections>;
loading: ComputedProperty<boolean>;
error: ComputedProperty<UseNewsletterErrors>;
updateNewsletterData: (params: NewsletterSections) => Promise<NewsletterSections>;
load: () => Promise<NewsletterSections>;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see few issues here:

  • Response from the API saved in the newsletter property will be different for every integration, so we cannot assume any signature. We need TypeScript's generic here, like NEWSLETTER.
  • We don't return any values from the load or update methods in any other composable, so to be consistent, both should return Promise<void>.
  • We don't know what properties might be needed in update method. I would suggest using generic here, like NEWSLETTER_UPDATE_PARAMS.
export interface UseNewsletter<NEWSLETTER, NEWSLETTER_UPDATE_PARAMS> {
  newsletter: ComputedProperty<NEWSLETTER>;
  loading: ComputedProperty<boolean>;
  error: ComputedProperty<UseNewsletterErrors>;
  updateNewsletterData: (params: NEWSLETTER_UPDATE_PARAMS) => Promise<void>;
  load: () => Promise<void>;
}

newsletterRef.value = await _factoryParams.updateNewsletterData(newsletter);
return newsletterRef.value;
} catch (err) {
error.value = err;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error.value.update = err;

Comment on lines +40 to +45
try {
const data = await updateNewsletterData(newsletter);
await onComplete(data);
} catch (error) {
onError(error);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the code you referred to is outdated. We no longer throw errors from methods. To check if the request was successful, refer to the error object from useNewsletter.


const loadedNewsletter = await load({});

expect(loadedNewsletter).toStrictEqual(defaultNewsletterData);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you use toStrictEqual, but below you use toMatchObject. If both are used for the same purpose, I'd suggest using toMatchObject because it better describes what we are expecting.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, as load shouldn't return any data, we should be comparing defautNewsletterData and newsletter object from useNewsletter composable.

@@ -0,0 +1,103 @@
<template>
<form
id="newsletter-form"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not using this anywhere, so it may be removed

<div class="form__checkbox-group">
<SfCheckbox
v-model="newsletter.woman"
@change="updateNewsletterField('woman', newsletter.woman)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it will change anything. Should we use !newsletter.woman or $event's value?

@filrak filrak deleted the bug-#5537/newsletter-and-profile branch March 19, 2021 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants