AW-3441 better test to find real problem. fixed the getValidPackages function.
All checks were successful
FarmMaps/FarmMapsLib/pipeline/head This commit looks good
All checks were successful
FarmMaps/FarmMapsLib/pipeline/head This commit looks good
This commit is contained in:
parent
122563a0bd
commit
a1a4fc14ab
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "farmmaps-lib-app",
|
||||
"version": "1.1.10",
|
||||
"version": "1.1.11",
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
"start": "ng serve",
|
||||
|
@ -35,7 +35,7 @@ export class HasPackageDirective implements OnDestroy, AfterViewInit {
|
||||
constructor(private hostTemplateRef: TemplateRef<any>, private viewContainerRef: ViewContainerRef,
|
||||
private store: Store<appCommonReducer.State>, private packageService: PackageService) {
|
||||
this.thenTemplate = hostTemplateRef;
|
||||
this.packSub = this.store.select(appCommonReducer.SelectGetUserPackages).subscribe((_) => {
|
||||
this.packSub = this.store.select(appCommonReducer.SelectGetValidUserPackages).subscribe((_) => {
|
||||
this.updateView();
|
||||
});
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
import {isValidPackage, PackageService} from './package.service';
|
||||
import {getValidPackages, isValidPackage, PackageService} from './package.service';
|
||||
import {MockStore, provideMockStore} from '@ngrx/store/testing';
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import * as appCommonReducer from '../reducers/app-common.reducer';
|
||||
import {reducer, State} from '../reducers/app-common.reducer';
|
||||
import * as appCommonActions from '../actions/app-common.actions';
|
||||
import {IItem} from '../models/item';
|
||||
import {IPackage} from '../models/package';
|
||||
|
||||
describe('PackageService', () => {
|
||||
const initialState = {userPackages: {}} as State;
|
||||
@ -38,25 +39,35 @@ describe('PackageService', () => {
|
||||
items = [
|
||||
{
|
||||
code: '123132',
|
||||
dataDate: '2022-01-25T00:00:00.000000Z',
|
||||
dataDate: '2021-01-25T00:00:00Z',
|
||||
dataEndDate: '2021-05-25T00:00:00Z',
|
||||
data: {
|
||||
id: 'vnd.farmmaps.package.zoning'
|
||||
}
|
||||
} as IItem,
|
||||
{
|
||||
code: '1231325',
|
||||
dataDate: '2021-01-25T00:00:00.000000Z',
|
||||
dataDate: '2021-01-25T00:00:00Z',
|
||||
dataEndDate: null,
|
||||
data: {
|
||||
id: 'vnd.farmmaps.package.zoning'
|
||||
}
|
||||
} as IItem,
|
||||
{
|
||||
code: '1231325',
|
||||
dataDate: '2022-01-25T00:00:00.000000Z',
|
||||
dataEndDate: '2022-05-25T00:00:00.000000Z',
|
||||
dataDate: '2022-01-25T00:00:00Z',
|
||||
dataEndDate: '2022-05-25T00:00:00Z',
|
||||
data: {
|
||||
id: 'vnd.farmmaps.package.tipstar'
|
||||
}
|
||||
} as IItem,
|
||||
{
|
||||
code: '1231325',
|
||||
dataDate: '2022-01-25T00:00:00Z',
|
||||
dataEndDate: null,
|
||||
data: {
|
||||
id: 'vnd.farmmaps.package.weather'
|
||||
}
|
||||
} as IItem
|
||||
];
|
||||
});
|
||||
@ -76,12 +87,36 @@ describe('PackageService', () => {
|
||||
|
||||
expect(Object.keys(initialState.userPackages).length).toBe(0);
|
||||
const state = reducer(initialState, action);
|
||||
expect(Object.keys(state.userPackages).length).toBe(2);
|
||||
expect(Object.keys(state.userPackages).length).toBe(3);
|
||||
expect(state.userPackages['vnd.farmmaps.package.zoning'].length).toBe(2);
|
||||
expect(state.userPackages['vnd.farmmaps.package.tipstar'].length).toBe(1);
|
||||
expect(state.userPackages['vnd.farmmaps.package.weather'].length).toBe(1);
|
||||
});
|
||||
|
||||
it('to validatePackage', () => {
|
||||
const action = new appCommonActions.InitUserPackagesSuccess(items);
|
||||
const state = reducer(initialState, action);
|
||||
|
||||
expect(isValidPackage(null)).toBe(false);
|
||||
expect(isValidPackage(state.userPackages['vnd.farmmaps.package.tipstar'][0])).toBe(true);
|
||||
expect(isValidPackage(state.userPackages['vnd.farmmaps.package.zoning'][0])).toBe(true);
|
||||
expect(isValidPackage(state.userPackages['vnd.farmmaps.package.zoning'][0])).toBe(false);
|
||||
expect(isValidPackage(state.userPackages['vnd.farmmaps.package.zoning'][1])).toBe(true);
|
||||
expect(isValidPackage(state.userPackages['vnd.farmmaps.package.weather'][0])).toBe(true);
|
||||
});
|
||||
|
||||
it('to getValidPackages', () => {
|
||||
const action = new appCommonActions.InitUserPackagesSuccess(items);
|
||||
const state = reducer(initialState, action);
|
||||
|
||||
const validPackages = getValidPackages(state.userPackages);
|
||||
|
||||
expect(Object.keys(validPackages).length).toBe(3);
|
||||
|
||||
// today is 27-01-2022, so the below package is not valid
|
||||
expect(validPackages['vnd.farmmaps.package.zoning']).not.toEqual({
|
||||
id: 'vnd.farmmaps.package.zoning',
|
||||
dataDate: '2021-01-25T00:00:00Z',
|
||||
dataEndDate: '2021-05-25T00:00:00Z'
|
||||
} as unknown as IPackage);
|
||||
});
|
||||
});
|
||||
|
@ -44,10 +44,9 @@ export function getValidPackages(packageMap: IPackages): {[key: string]: IPackag
|
||||
return packages.length > 0;
|
||||
}).reduce((map, key) => {
|
||||
const packages = packageMap[key];
|
||||
return {
|
||||
...map,
|
||||
key: packages[0]
|
||||
};
|
||||
const newMap = {...map};
|
||||
newMap[key] = packages.find(p => isValidPackage(p));
|
||||
return newMap;
|
||||
}, {});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user