Skip to content

Commit

Permalink
Merge pull request #79 from alma/feature/pre-commit-hook
Browse files Browse the repository at this point in the history
Implement pre-commit hook
  • Loading branch information
joyet-simon authored Sep 20, 2023
2 parents e73c545 + a43918d commit a5b923a
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 40 deletions.
8 changes: 8 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"node": true,
"esversion": 8,
"predef": [
"describe",
"it"
]
}
61 changes: 61 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
args: ["--maxkb=1024"]
- id: detect-private-key
- id: check-merge-conflict

- repo: https://github.com/pre-commit/mirrors-jshint
rev: v2.13.6
hooks:
- id: jshint
files: "(^.*\\.js$)"

- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.29.0
hooks:
- id: eslint
files: "(^cartridges/int_alma/cartridge/.*\\.js$)"# *.js, *.jsx, *.ts and *.tsx
types: [file]
args:
- --fix

- repo: https://github.com/thibaudcolas/pre-commit-stylelint
rev: v14.16.0
hooks:
- id: stylelint
files: "(^cartridges/int_alma/cartridge/static/default/css/.*\\.css$)"
args:
- --config
- .stylelintrc.json
additional_dependencies:
- [email protected]
- [email protected]
- [email protected]
- [email protected]

# - repo: https://github.com/returntocorp/semgrep
# rev: v1.27.0
# hooks:
# - id: semgrep
# args:
# - --error
# - --config
# - semgrep/rules/
# - --metrics
# - "off"
# - --quiet
# - --disable-version-check
# - --skip-unknown-extensions
# pass_filenames: false # Passing files explicitely override semgremignore

- repo: https://github.com/alma/pre-commit-hooks
rev: 1.1.2
hooks:
- id: check-branch-name
args:
- "-r^((chore|ci|dependabot|devx|docs|feature|fix|hotfix|hotfix-backport|infra|other|perf|refactor|security|test)\/.+|(snyk)-.+|main|HEAD)$$"
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ var paymentMethodId = '';
* @returns {string} the custom site preference name
*/
function getSelectorNameFromPlan(plan) {
return 'ALMA_general_'
// number of installments (p1x, p3x, p4x, ....)
+ plan.installments_count + '_'
// by how many days is the payment defered
+ plan.deferred_days
;
// ALMA_general + number of installments (p1x, p3x, p4x, ....) + by how many days is the payment defered
return 'ALMA_general_' + plan.installments_count + '_' + plan.deferred_days;
}

/**
Expand Down Expand Up @@ -210,9 +206,7 @@ function getPlanPaymentMethodID(plan) {
if (plan.deferred_days > 0 && planIsActivated(PaymentMgr.getPaymentMethod(ALMA_DEFERRED_ID), plan)) {
paymentMethodId = ALMA_DEFERRED_ID;
}
if (plan.installments_count === 1
&& plan.deferred_days === 0
&& planIsActivated(PaymentMgr.getPaymentMethod(ALMA_PAY_NOW_ID), plan)) {
if (plan.installments_count === 1 && plan.deferred_days === 0 && planIsActivated(PaymentMgr.getPaymentMethod(ALMA_PAY_NOW_ID), plan)) {
paymentMethodId = ALMA_PAY_NOW_ID;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ function isOnShipmentPaymentEnabled(installmentsCount, deferredDays) {
return plan.installments_count === parseInt(installmentsCount, 10) && plan.deferred_days === parseInt(deferredDays, 10);
});

return Site.getCurrent().getCustomPreferenceValue('ALMA_On_Shipment_Payment')
&& requestedPlan !== null
&& requestedPlan.deferred_trigger_limit_days !== null;
return Site.getCurrent()
.getCustomPreferenceValue('ALMA_On_Shipment_Payment') && requestedPlan !== null && requestedPlan.deferred_trigger_limit_days !== null;
}

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';

var pkg = require('../../../package.json');

/**
Expand Down
10 changes: 3 additions & 7 deletions cartridges/int_alma/cartridge/scripts/helpers/almaPlanHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ function getFeePlans() {
* @returns {string} site preference name
*/
function getSitePrefNameFromPlan(plan) {
return 'ALMA_general_'
// number of installments (p1x, p3x, p4x, ....)
+ plan.installments_count + '_'
// by how many days is the payment deferred
+ plan.deferred_days
// ALMA_general + number of installments (p1x, p3x, p4x, ....) + by how many days is the payment deferred
return 'ALMA_general_' + plan.installments_count + '_' + plan.deferred_days
;
}

Expand Down Expand Up @@ -77,8 +74,7 @@ function applyMerchantConfig(currentPlan) {
* @returns {Object} plan any alma plan
*/
function filterWithMerchantConfig(plan, purchaseAmount) {
return (purchaseAmount > (plan.min_display_amount / 100))
&& (purchaseAmount < (plan.max_display_amount / 100));
return (purchaseAmount > (plan.min_display_amount / 100)) && (purchaseAmount < (plan.max_display_amount / 100));
}

/**
Expand Down
8 changes: 4 additions & 4 deletions cartridges/int_alma/cartridge/scripts/steps/CheckRefund.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
*/
function isOrderToBeRefund(order) {
return (
order.custom.almaRefundType.toString() === 'Total'
|| (order.custom.almaRefundType.toString() === 'Partial'
&& order.custom.almaWantedRefundAmount > 0
&& order.custom.almaWantedRefundAmount < order.totalGrossPrice.value)
order.custom.almaRefundType.toString() === 'Total' || (
order.custom.almaRefundType.toString() === 'Partial' && order.custom.almaWantedRefundAmount > 0 && order.custom.almaWantedRefundAmount < order.totalGrossPrice.value
)
);
}

Expand Down Expand Up @@ -66,6 +65,7 @@ exports.execute = function () {
Logger.info('Partial refund is not yet implemented with deferred payment - order id {0}', [orderItem.orderNo]);
}

/* jshint loopfunc: true */
// eslint-disable-next-line no-loop-func
Transaction.wrap(function () {
orderItem.custom.ALMA_Deferred_Capture = deferredStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.alma-content .pay-type {
/* background: #cccccc7a;*/
border-radius: 5px;
margin-top: 10px;
cursor: pointer;
Expand Down Expand Up @@ -42,11 +41,11 @@
}

.alma-content .pay-type p {
color: var(--color-grey6);
color: var(--color-grey6);
}

.alma-content .pay-type .no-margin {
margin-bottom: 0px;
margin-bottom: 0;
}

.alma-content .loading {
Expand Down Expand Up @@ -86,7 +85,8 @@
.alma-lds-ring div:nth-child(3) {
animation-delay: -0.15s;
}
.alma-error-message{

.alma-error-message {
color: red;
font-size: small;
text-align: center;
Expand Down
1 change: 1 addition & 0 deletions test/mocks/helpers/almaOrderHelpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';

var sinon = require('sinon');
var proxyquire = require('proxyquire')
.noCallThru()
Expand Down
28 changes: 15 additions & 13 deletions test/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';

var ArrayList = require('./mocks/dw.util.Collection');

module.exports = function toProductMock(mock) {
Expand All @@ -8,20 +9,21 @@ module.exports = function toProductMock(mock) {

var result = {};
if (typeof mock === 'object') {
Object.keys(mock).forEach(function (item) {
if (typeof mock[item] === 'object') {
if (mock[item] && mock[item].type === 'function') {
var innerMock = typeof mock[item].return !== 'undefined'
? toProductMock(mock[item].return)
: toProductMock(mock[item]);
result[item] = function () { return innerMock; };
} else {
result[item] = toProductMock(mock[item]);
Object.keys(mock)
.forEach(function (item) {
if (typeof mock[item] === 'object') {
if (mock[item] && mock[item].type === 'function') {
var innerMock = typeof mock[item].return !== 'undefined' ? toProductMock(mock[item].return) : toProductMock(mock[item]);
result[item] = function () {
return innerMock;
};
} else {
result[item] = toProductMock(mock[item]);
}
} else if (item !== 'function' || item !== 'return') {
result[item] = mock[item];
}
} else if (item !== 'function' || item !== 'return') {
result[item] = mock[item];
}
});
});
} else {
result = mock;
}
Expand Down

0 comments on commit a5b923a

Please sign in to comment.