Skip to content

Commit

Permalink
fix: rework category completeness computation (#1276)
Browse files Browse the repository at this point in the history
* so more complete data overwrites less complete one
* categoryRef was missing for categories that should already have this information
  • Loading branch information
shauke authored Sep 16, 2022
1 parent f7e3d81 commit a6783cc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
38 changes: 31 additions & 7 deletions src/app/core/models/category/category.mapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,41 @@ describe('Category Mapper', () => {
it('should return -1 for falsy inputs', () => {
expect(categoryMapper.computeCompleteness(undefined)).toEqual(-1);
});
it('should return 0 for input from top level call', () => {
it('should return 0 for input from category path categories', () => {
expect(categoryMapper.computeCompleteness({ uri: 'some' } as CategoryData)).toEqual(0);
});
it('should return 1 for input from subcategories from category call', () => {
expect(categoryMapper.computeCompleteness({ uri: 'some', images: [{}] } as CategoryData)).toEqual(1);
it('should return 1 for input from sub categories', () => {
expect(categoryMapper.computeCompleteness({ uri: 'some', categoryRef: 'some@demo' } as CategoryData)).toEqual(1);
});
it('should return 2 for input from categories call', () => {
expect(categoryMapper.computeCompleteness({ images: [{}], categoryPath: [{}, {}] } as CategoryData)).toEqual(2);
it('should return 2 for root categories from top level categories call', () => {
expect(
categoryMapper.computeCompleteness({
uri: 'some',
categoryRef: 'some@demo',
categoryPath: [{}],
} as CategoryData)
).toEqual(2);
});
it('should return 3 for input from categories call with root categories', () => {
expect(categoryMapper.computeCompleteness({ categoryPath: [{}], attributes: [] } as CategoryData)).toEqual(3);
it('should return 2 for sub categories from categories call', () => {
expect(
categoryMapper.computeCompleteness({
uri: 'some',
categoryRef: 'some@demo',
images: [{}],
categoryPath: [{}, {}],
} as CategoryData)
).toEqual(2);
});
it('should return 3 for input from categories call', () => {
expect(
categoryMapper.computeCompleteness({
uri: 'some',
categoryRef: 'some@demo',
images: [{}],
categoryPath: [{}, {}],
seoAttributes: {},
} as CategoryData)
).toEqual(3);
});
});

Expand Down
16 changes: 8 additions & 8 deletions src/app/core/models/category/category.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,20 @@ export class CategoryMapper {
// adjust CategoryCompletenessLevel.Max accordingly
let count = 0;

if (!categoryData.uri) {
// returned subcategories and elements from the top-level category call contain uri
if (categoryData.categoryRef) {
// category path categories do not contain a categoryRef
count++;
}
if (categoryData.images) {
// images are not supplied with top level category call
if (categoryData.categoryPath && categoryData.categoryPath.length === 1) {
// root categories have no images but a single-entry categoryPath
count++;
}
if (categoryData.attributes) {
// attributes are not supplied for subcategories
if (categoryData.images) {
// images are supplied for sub categories in the category details call
count++;
}
if (categoryData.categoryPath && categoryData.categoryPath.length === 1) {
// root categories have no images but a single-entry categoryPath
if (categoryData.seoAttributes) {
// seo attributes are only supplied with the category details call
count++;
}

Expand Down

0 comments on commit a6783cc

Please sign in to comment.