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

(arc-SaaS): Add test cases on Commands #108

Open
wants to merge 3 commits into
base: master
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
9 changes: 0 additions & 9 deletions projects/saas-ui/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,4 @@ describe('AppComponent', () => {
const app = fixture.componentInstance;
expect(app.title).toEqual('saas-ui');
});

it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('.content span')?.textContent).toContain(
'saas-ui app is running!',
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {ApiService, IAdapter} from '@project-lib/core/api';

import {IAnyObject} from '@project-lib/core/i-any-object';
import {Feature} from '../../shared/interfaces/features';
import {of, throwError} from 'rxjs';
import {AddFeaturesForPlanCommand} from './add-features-for-plan.command';

describe('AddFeaturesForPlanCommand', () => {
let addFeaturesForPlanCommand: AddFeaturesForPlanCommand<Feature[]>;
let apiService: jasmine.SpyObj<ApiService>;
let adapter: jasmine.SpyObj<IAdapter<Feature[]>>;
let appConfig: IAnyObject;
const planId = 'plan123';

beforeEach(() => {
apiService = jasmine.createSpyObj<ApiService>('ApiService', ['post']);
adapter = jasmine.createSpyObj('IAdapter', ['adapt']);
appConfig = {
baseApiUrl: 'https://api.example.com',
subscriptionServiceUrl: '/subscription',
};

addFeaturesForPlanCommand = new AddFeaturesForPlanCommand(
apiService,
adapter,
planId,
appConfig,
);
});

it('should create an instance of AddFeaturesForPlanCommand', () => {
expect(addFeaturesForPlanCommand).toBeTruthy();
});
});
28 changes: 28 additions & 0 deletions projects/saas-ui/src/app/main/commands/add-tenant.command.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {ApiService, IAdapter, PostAPICommand} from '@project-lib/core/api';
import {Tenant} from '../../shared/models';
import {IAnyObject} from '@project-lib/core/i-any-object';
import {AddTenantCommand} from './add-tenant.command';

describe('AddTenantCommand', () => {
let addTenantCommand: AddTenantCommand<Tenant>;
let apiService: jasmine.SpyObj<ApiService>;
let adapter: jasmine.SpyObj<IAdapter<Tenant>>;
let appConfig: jasmine.SpyObj<IAnyObject>;

beforeEach(() => {
apiService = jasmine.createSpyObj<ApiService>('ApiService', ['post']);
adapter = jasmine.createSpyObj('IAdapter', ['adapt']);
appConfig = jasmine.createSpyObj<IAnyObject>('IAnyObject', [
'baseApiUrl',
'tenantmgmtServiceUrl',
]);
appConfig.baseApiUrl = 'https://api.example.com';
appConfig.tenantmgmtServiceUrl = '/tenant-management';

addTenantCommand = new AddTenantCommand(apiService, adapter, appConfig);
});

it('should create an instance of AddTenantCommand', () => {
expect(addTenantCommand).toBeTruthy();
});
});
48 changes: 48 additions & 0 deletions projects/saas-ui/src/app/main/commands/delete-plan.command.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {ApiService, DelAPICommand, IAdapter} from '@project-lib/core/api';

import {IAnyObject} from '@project-lib/core/i-any-object';
import {of, throwError} from 'rxjs';
import {DeletePlanCommand} from './delete-plan.command';

describe('DeletePlanCommand', () => {
let deletePlanCommand: DeletePlanCommand<any>;
let apiService: jasmine.SpyObj<ApiService>;
let adapter: jasmine.SpyObj<IAdapter<any>>;
let appConfig: jasmine.SpyObj<IAnyObject>;
const planId = '123';

beforeEach(() => {
apiService = jasmine.createSpyObj<ApiService>('ApiService', ['delete']);
adapter = jasmine.createSpyObj('IAdapter', ['adapt']);
appConfig = jasmine.createSpyObj<IAnyObject>('IAnyObject', [
'baseApiUrl',
'subscriptionServiceUrl',
]);
appConfig.baseApiUrl = 'https://api.example.com';
appConfig.subscriptionServiceUrl = '/subscription';

deletePlanCommand = new DeletePlanCommand(
apiService,
adapter,
planId,
appConfig,
);
});

it('should create an instance of DeletePlanCommand', () => {
expect(deletePlanCommand).toBeTruthy();
});

it('should handle errors from the ApiService', done => {
const errorResponse = new Error('API error');
apiService.delete.and.returnValue(throwError(() => errorResponse));

deletePlanCommand.execute().subscribe({
next: () => done.fail('Expected an error, but got success'),
error: error => {
expect(error).toBe(errorResponse);
done();
},
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {ApiService, IAdapter} from '@project-lib/core/api';
import {IAnyObject} from '@project-lib/core/i-any-object';
import {of, throwError} from 'rxjs';
import {DeleteTenantCommand} from './delete-tenant.command';

describe('DeleteTenantCommand', () => {
let deleteTenantCommand: DeleteTenantCommand<any>;
let apiService: jasmine.SpyObj<ApiService>;
let adapter: jasmine.SpyObj<IAdapter<any>>;
let appConfig: jasmine.SpyObj<IAnyObject>;
const tenantId = 'tenant123';

beforeEach(() => {
apiService = jasmine.createSpyObj<ApiService>('ApiService', ['delete']);
adapter = jasmine.createSpyObj('IAdapter', ['adapt']);
appConfig = jasmine.createSpyObj<IAnyObject>('IAnyObject', [
'baseApiUrl',
'tenantmgmtServiceUrl',
]);
appConfig.baseApiUrl = 'https://api.example.com';
appConfig.tenantmgmtServiceUrl = '/tenantmgmt';

deleteTenantCommand = new DeleteTenantCommand(
apiService,
adapter,
tenantId,
appConfig,
);
});

it('should create an instance of DeleteTenantCommand', () => {
expect(deleteTenantCommand).toBeTruthy();
});

it('should handle errors from the ApiService', done => {
const errorResponse = new Error('API error');
apiService.delete.and.returnValue(throwError(() => errorResponse));

deleteTenantCommand.execute().subscribe({
next: () => done.fail('Expected an error, but got success'),
error: error => {
expect(error).toBe(errorResponse);
done();
},
});
});
});
42 changes: 42 additions & 0 deletions projects/saas-ui/src/app/main/commands/edit-tenant.command.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {ApiService, IAdapter} from '@project-lib/core/api';
import {IAnyObject} from '@project-lib/core/i-any-object';
import {Tenant} from '../../shared/models/tenant.model';
import {of, throwError} from 'rxjs';
import {EditTenantCommand} from './edit-tenant.command';

describe('EditTenantCommand', () => {
let editTenantCommand: EditTenantCommand<any>;
let apiService: jasmine.SpyObj<ApiService>;
let adapter: jasmine.SpyObj<IAdapter<any>>;
let appConfig: IAnyObject;
const tenantId = 'tenant123';
const tenantData: Tenant = {
id: tenantId,
name: 'Tenant Test Name',
description: 'A sample description for the tenant',
// Include other necessary tenant fields here
};

beforeEach(() => {
apiService = jasmine.createSpyObj<ApiService>('ApiService', ['patch']);
adapter = jasmine.createSpyObj('IAdapter', ['adapt']);
appConfig = jasmine.createSpyObj<IAnyObject>('IAnyObject', [
'baseApiUrl',
'tenantmgmtServiceUrl',
]);
appConfig.baseApiUrl = 'https://api.example.com';
appConfig.tenantmgmtServiceUrl = '/tenantmgmt';

editTenantCommand = new EditTenantCommand(
apiService,
adapter,
tenantId,
appConfig,
);
editTenantCommand.data = tenantData;
});

it('should create an instance of EditTenantCommand', () => {
expect(editTenantCommand).toBeTruthy();
});
});
60 changes: 60 additions & 0 deletions projects/saas-ui/src/app/main/commands/get-plan.command.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {IApiService, IAdapter} from '@project-lib/core/api';
import {IAnyObject} from '@project-lib/core/i-any-object';
import {Plan} from '../../shared/models';
import {of, throwError} from 'rxjs';
import {GetPlanCommand} from './get-plan.command';

describe('GetPlanCommand', () => {
let getPlanCommand: GetPlanCommand<Plan[]>;
let apiService: jasmine.SpyObj<IApiService>;
let adapter: jasmine.SpyObj<IAdapter<Plan[]>>;
let appConfig: IAnyObject;
const mockPlans = [
{
id: 'plan1',
name: 'Basic Plan',
description: 'Basic plan description',
price: 10,
currency: 'USD',
cycle: 'monthly',
tier: 'basic',
},
{
id: 'plan2',
name: 'Premium Plan',
description: 'Premium plan description',
price: 50,
currency: 'USD',
cycle: 'monthly',
tier: 'premium',
},
];

beforeEach(() => {
apiService = jasmine.createSpyObj<IApiService>('IApiService', ['get']);
adapter = jasmine.createSpyObj('IAdapter', ['adapt']);
appConfig = {
baseApiUrl: 'https://api.example.com',
subscriptionServiceUrl: '/subscription',
};

getPlanCommand = new GetPlanCommand(apiService, adapter, appConfig);
});

it('should create an instance of GetPlanCommand', () => {
expect(getPlanCommand).toBeTruthy();
});

it('should handle errors from the ApiService', done => {
const errorResponse = new Error('API error');
apiService.get.and.returnValue(throwError(() => errorResponse));

getPlanCommand.execute().subscribe({
next: () => done.fail('Expected an error, but got success'),
error: error => {
expect(error).toBe(errorResponse);
done();
},
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {ApiService, IAdapter} from '@project-lib/core/api';
import {IAnyObject} from '@project-lib/core/i-any-object';
import {of, throwError} from 'rxjs';
import {GetTenantByIdCommand} from './get-tenant-by-id.command';

describe('GetTenantByIdCommand', () => {
let getTenantByIdCommand: GetTenantByIdCommand<any>;
let apiService: jasmine.SpyObj<ApiService>;
let adapter: jasmine.SpyObj<IAdapter<any>>;
let appConfig: IAnyObject;
const tenantId = 'tenant123';
const mockTenantData = {
id: tenantId,
name: 'Tenant Name',
address: '123 Main St',
};

beforeEach(() => {
apiService = jasmine.createSpyObj<ApiService>('ApiService', ['get']);
adapter = jasmine.createSpyObj('IAdapter', ['adapt']);
appConfig = {
baseApiUrl: 'https://api.example.com',
tenantmgmtServiceUrl: '/tenantmgmt',
};

getTenantByIdCommand = new GetTenantByIdCommand(
apiService,
adapter,
tenantId,
appConfig,
);
});

it('should create an instance of GetTenantByIdCommand', () => {
expect(getTenantByIdCommand).toBeTruthy();
});

it('should handle errors from the ApiService', done => {
const errorResponse = new Error('API error');
apiService.get.and.returnValue(throwError(() => errorResponse));

getTenantByIdCommand.execute().subscribe({
next: () => done.fail('Expected an error, but got success'),
error: error => {
expect(error).toBe(errorResponse);
done();
},
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {ApiService, IAdapter} from '@project-lib/core/api';

import {IAnyObject} from '@project-lib/core/i-any-object';
import {TenantDetails} from '../../shared/models/tenantDetails.model';
import {of, throwError} from 'rxjs';
import {GetTenantDetailsCommand} from './get-tenant-details.command';

describe('GetTenantDetailsCommand', () => {
let getTenantDetailsCommand: GetTenantDetailsCommand<TenantDetails[]>;
let apiService: jasmine.SpyObj<ApiService>;
let adapter: jasmine.SpyObj<IAdapter<TenantDetails[]>>;
let appConfig: IAnyObject;

beforeEach(() => {
apiService = jasmine.createSpyObj<ApiService>('ApiService', ['get']);
adapter = jasmine.createSpyObj('IAdapter', ['adapt']);
appConfig = {
baseApiUrl: 'https://api.example.com',
tenantMgmtFacadeUrl: '/tenantmgmt-facade',
};

getTenantDetailsCommand = new GetTenantDetailsCommand(
apiService,
adapter,
appConfig,
);
});

it('should create an instance of GetTenantDetailsCommand', () => {
expect(getTenantDetailsCommand).toBeTruthy();
});

it('should handle errors from the ApiService', done => {
const errorResponse = new Error('API error');
apiService.get.and.returnValue(throwError(() => errorResponse));

getTenantDetailsCommand.execute().subscribe({
next: () => done.fail('Expected an error, but got success'),
error: error => {
expect(error).toBe(errorResponse);
done();
},
});
});
});
Loading