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

feat(discount-codes): implement function to generate codes #147

Merged
merged 4 commits into from
May 3, 2017

Conversation

wizzy25
Copy link
Contributor

@wizzy25 wizzy25 commented Apr 30, 2017

affects: @commercetools/discount-code-generator

Summary

Implement the discount code generator function as part of this checklist

affects: @commercetools/discount-code-generator
@wizzy25 wizzy25 self-assigned this Apr 30, 2017
@codecov-io
Copy link

codecov-io commented Apr 30, 2017

Codecov Report

Merging #147 into 142-code-generator-main will increase coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@                     Coverage Diff                     @@
##           142-code-generator-main     #147      +/-   ##
===========================================================
+ Coverage                    97.06%   97.11%   +0.04%     
===========================================================
  Files                           53       53              
  Lines                          989     1004      +15     
===========================================================
+ Hits                           960      975      +15     
  Misses                          29       29
Impacted Files Coverage Δ
packages/discount-code-generator/src/main.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 52b04ab...68d9af7. Read the comment docs.

CodeData,
CodeDataArray,
CodeOptions,
} from 'types/sdk'
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the types/sdk file is getting large, separate out your type declarations to another file...

// en: 'bar'
// },
// cartDiscounts: [],
// cartPredicate: 'some predicate',
Copy link
Contributor

Choose a reason for hiding this comment

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

Use multi-line comment in javascript

// }

export default function discountCodeGenerator (
options: CodeOptions,
Copy link
Contributor

Choose a reason for hiding this comment

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

You can wrap all params in one object, except there is possibiliity you reuse each later

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Params are currently in one options object. The data object is the one being mutated

if (!prefix.length)
return code

const codePrefix = prefix.toUpperCase()
Copy link
Contributor

Choose a reason for hiding this comment

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

why you forcing to uppercase?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can the discount codes be in lowercase or mixed?

Copy link
Contributor Author

@wizzy25 wizzy25 May 2, 2017

Choose a reason for hiding this comment

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

Semantics 😇😇
It is case-sensitive. Thought it wasn't so I was forcing it all to uppercase 😃


codes.forEach((codeObject) => {
expect(codeObject).toMatchObject(data)
expect(codeObject.code).toBeTruthy()
Copy link
Contributor

Choose a reason for hiding this comment

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

The next assertion made this assertion redundant

affects: @commercetools/discount-code-generator
@wizzy25
Copy link
Contributor Author

wizzy25 commented May 2, 2017

@hisabimbola updated changes, kindly review :)

Copy link
Member

@emmenko emmenko left a comment

Choose a reason for hiding this comment

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

I left some small comments, but it looks good 👍

* cartDiscounts: [],
* cartPredicate: 'some predicate',
* isActive: true,
* maxApplicationsPerCustomer: 10,
Copy link
Member

Choose a reason for hiding this comment

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

cartDiscounts: [];
cartPredicate?: string;
isActive: boolean;
maxApplicationsPerCustomer?: number;
Copy link
Member

Choose a reason for hiding this comment

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

* prefix: CT,
* }

* The {data} should have the attributes of the discount codes
Copy link
Member

Choose a reason for hiding this comment

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

affects: @commercetools/discount-code-generator
* }
*
* More information about the discount codes can be found here: http://
* dev.commercetools.com/http-api-projects-discountCodes.html#discountcode
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will this be the best way to add this link without annoying eslint? 🤔 Cc @hisabimbola @emmenko

Copy link
Member

Choose a reason for hiding this comment

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

You can simply disable eslint for such comments ;)

affects: @commercetools/discount-code-generator
@wizzy25 wizzy25 merged commit f741a4a into 142-code-generator-main May 3, 2017
@wizzy25 wizzy25 deleted the generator-function branch May 3, 2017 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants