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

Feature/ad 280 #23

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ testem.log
# System files
.DS_Store
Thumbs.db
/package-lock.json
100 changes: 93 additions & 7 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,124 @@
"version": 1,
"newProjectRoot": "projects",
"projects": {
"adyen-payments": {
"@adyen/adyen-spartacus": {
"projectType": "library",
"root": "projects/adyen-payments",
"sourceRoot": "projects/adyen-payments/src",
"root": "projects/adyen/adyen-spartacus",
"sourceRoot": "projects/adyen/adyen-spartacus/src",
"prefix": "lib",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:ng-packagr",
"options": {
"project": "projects/adyen-payments/ng-package.json"
"project": "projects/adyen/adyen-spartacus/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "projects/adyen-payments/tsconfig.lib.prod.json"
"tsConfig": "projects/adyen/adyen-spartacus/tsconfig.lib.prod.json"
},
"development": {
"tsConfig": "projects/adyen-payments/tsconfig.lib.json"
"tsConfig": "projects/adyen/adyen-spartacus/tsconfig.lib.json"
}
},
"defaultConfiguration": "production"
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"tsConfig": "projects/adyen-payments/tsconfig.spec.json",
"tsConfig": "projects/adyen/adyen-spartacus/tsconfig.spec.json",
"polyfills": [
"zone.js",
"zone.js/testing"
]
}
}
}
},
"showcase":{
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
}
},
"root": "projects/showcase",
"sourceRoot": "projects/showcase/src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:application",
"options": {
"outputPath": "dist/showcase",
"index": "projects/showcase/src/index.html",
"browser": "projects/showcase/src/main.ts",
"polyfills": [
"zone.js"
],
"tsConfig": "projects/showcase/tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
"projects/showcase/src/favicon.ico",
"projects/showcase/src/assets",
{
"glob": "**/*",
"input": "./node_modules/@spartacus/smartedit/assets",
"output": "assets/"
}
],
"styles": [
"projects/showcase/src/styles.scss",
"projects/showcase/src/styles/spartacus/user.scss",
"projects/showcase/src/styles/spartacus/cart.scss",
"projects/showcase/src/styles/spartacus/order.scss",
"projects/showcase/src/styles/spartacus/checkout.scss",
"projects/showcase/src/styles/spartacus/storefinder.scss",
"projects/showcase/src/styles/spartacus/asm.scss",
"projects/showcase/src/styles/spartacus/product.scss"
],
"scripts": [],
"stylePreprocessorOptions": {
"includePaths": [
"node_modules/"
]
}
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "3.5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"outputHashing": "all"
},
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"buildTarget": "showcase:build:production"
},
"development": {
"buildTarget": "showcase:build:development"
}
},
"defaultConfiguration": "development"
}
}
}
}
}
42 changes: 35 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,24 @@
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
"start": "npm-run-all clean --parallel lib:watch showcase:start-waiton",
"build": "run-s lib:build showcase:build",
"test": "run-p lib:test showcase:test",
"test-coverage": "run-p lib:test-coverage showcase:test-coverage",
"lib:build": "ng build @adyen/adyen-spartacus",
"lib:watch": "ng build @adyen/adyen-spartacus --watch --configuration development",
"lib:test": "ng test @adyen/adyen-spartacus",
"lib:test-coverage": "ng test @adyen/adyen-spartacus --no-watch --code-coverage",
"lib:prebuild": "cd projects/adyen/spartacus-payment && npm version patch -m \"Upgrade to %s for build\" ",
"lib:schematics": "tsc -p tsconfig.schematics.json",
"lib:postbuild": "copyfiles schematics/*/files/** schematics/collection.json ../../dist/adyen-payments/",
"showcase:start-waiton": "wait-on dist/adyen/adyen-spartacus/package.json && npm run showcase:start",
"showcase:start": "ng serve showcase",
"showcase:build": "ng build showcase",
"showcase:watch": "ng build showcase --watch --configuration development",
"showcase:test": "ng test showcase",
"showcase:test-coverage": "ng test showcase --no-watch --code-coverage",
"clean": "rimraf dist"
},
"dependencies": {
"@adyen/adyen-web": "6.3.0",
Expand All @@ -18,10 +32,21 @@
"@angular/platform-browser": "^17.3.0",
"@angular/platform-browser-dynamic": "^17.3.0",
"@angular/router": "^17.3.0",
"@spartacus/asm": "~2211.23.0-1",
"@spartacus/assets": "~2211.23.0-1",
"@spartacus/cart": "~2211.23.0-1",
"@spartacus/checkout": "~2211.23.0-1",
"@spartacus/core": "~2211.23.0-1",
"@spartacus/order": "~2211.23.0-1",
"@spartacus/pdf-invoices": "~2211.23.0-1",
"@spartacus/product": "~2211.23.0-1",
"@spartacus/smartedit": "~2211.23.0-1",
"@spartacus/storefinder": "~2211.23.0-1",
"@spartacus/storefront": "~2211.23.0-1",
"@spartacus/checkout": "~2211.23.0-1",
"@spartacus/cart": "~2211.23.0-1",
"@spartacus/styles": "~2211.23.0-1",
"@spartacus/tracking": "~2211.23.0-1",
"@spartacus/user": "~2211.23.0-1",
"adyen-payments": "^1.0.6",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.3"
Expand All @@ -38,6 +63,9 @@
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.1.0",
"ng-packagr": "^17.3.0",
"typescript": "~5.4.2"
"npm-run-all": "^4.1.5",
"rimraf": "^6.0.1",
"typescript": "~5.4.2",
"wait-on": "^7.2.0"
}
}

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions projects/adyen-payments/src/public-api.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/adyen-payments",
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../../dist/adyen/adyen-spartacus",
"lib": {
"entryFile": "src/public-api.ts"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
{
"name": "adyen-payments",
"name": "@adyen/adyen-spartacus",
"version": "1.0.0",
"scripts": {
"prebuild": "npm version patch -m \"Upgrade to %s for build\"",
"build": "ng build && tsc -p tsconfig.schematics.json",
"postbuild": "copyfiles schematics/*/files/** schematics/collection.json ../../dist/adyen-payments/"
},
"schematics": "./schematics/collection.json",
"peerDependencies": {
"@adyen/adyen-web": "6.3.0",
"@angular/common": "^17.3.0",
"@angular/core": "^17.3.0"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { of } from 'rxjs';
import { AdyenRedirectErrorComponent } from './adyen-redirect-error.component';
import { RoutingService, GlobalMessageService, GlobalMessageType, OCC_CART_ID_CURRENT, TranslationService, UserIdService } from '@spartacus/core';
import { MultiCartFacade } from '@spartacus/cart/base/root';

describe('AdyenRedirectErrorComponent', () => {
let component: AdyenRedirectErrorComponent;
let fixture: ComponentFixture<AdyenRedirectErrorComponent>;
let mockRoutingService: jasmine.SpyObj<RoutingService>;
let mockGlobalMessageService: jasmine.SpyObj<GlobalMessageService>;
let mockTranslationService: jasmine.SpyObj<TranslationService>;
let mockUserIdService: jasmine.SpyObj<UserIdService>;
let mockMultiCartFacade: jasmine.SpyObj<MultiCartFacade>;

beforeEach(async () => {
mockRoutingService = jasmine.createSpyObj('RoutingService', ['getParams', 'go']);
mockGlobalMessageService = jasmine.createSpyObj('GlobalMessageService', ['add']);
mockTranslationService = jasmine.createSpyObj('TranslationService', ['translate']);
mockUserIdService = jasmine.createSpyObj('UserIdService', ['takeUserId']);
mockMultiCartFacade = jasmine.createSpyObj('MultiCartFacade', ['reloadCart', 'loadCart', 'getCartIdByType']);

mockRoutingService.getParams.and.returnValue(of({ errorCode: btoa('someErrorCode') }));
mockTranslationService.translate.and.returnValue(of('translatedMessage'));
mockUserIdService.takeUserId.and.returnValue(of('userId'));
mockMultiCartFacade.getCartIdByType.and.returnValue(of('cartId'));

await TestBed.configureTestingModule({
declarations: [AdyenRedirectErrorComponent],
providers: [
{ provide: RoutingService, useValue: mockRoutingService },
{ provide: GlobalMessageService, useValue: mockGlobalMessageService },
{ provide: TranslationService, useValue: mockTranslationService },
{ provide: UserIdService, useValue: mockUserIdService },
{ provide: MultiCartFacade, useValue: mockMultiCartFacade }
]
}).compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(AdyenRedirectErrorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should add error message and reload cart on init', () => {
const errorCode = 'someErrorCode';
const translatedMessage = 'translatedMessage';
const userId = 'userId';
const cartId = 'cartId';

mockRoutingService.getParams.and.returnValue(of({ errorCode: btoa(errorCode) }));
mockTranslationService.translate.and.returnValue(of(translatedMessage));
mockUserIdService.takeUserId.and.returnValue(of(userId));
mockMultiCartFacade.getCartIdByType.and.returnValue(of(cartId));

component.ngOnInit();

expect(mockTranslationService.translate).toHaveBeenCalledWith(component['placeOrderErrorCodePrefix'] + errorCode);
expect(mockGlobalMessageService.add).toHaveBeenCalledWith(translatedMessage, GlobalMessageType.MSG_TYPE_ERROR, component['messageTimeout']);
expect(mockMultiCartFacade.reloadCart).toHaveBeenCalledWith(OCC_CART_ID_CURRENT);
expect(mockMultiCartFacade.loadCart).toHaveBeenCalledWith({ cartId: OCC_CART_ID_CURRENT, userId });
expect(mockRoutingService.go).toHaveBeenCalledWith({ cxRoute: 'checkoutAdyenPaymentDetails' });
});

it('should unsubscribe from all subscriptions on destroy', () => {
spyOn(component['subscriptions'], 'unsubscribe');
component.ngOnDestroy();
expect(component['subscriptions'].unsubscribe).toHaveBeenCalled();
});
});
Loading
Loading