Skip to content

Commit c393cac

Browse files
committed
dynamically resolve catalogItem from catalog at Scroll initialization time
1 parent 47d9762 commit c393cac

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/scroll/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { CatalogItem } from '../catalog/item/index.js';
2-
31
export class Scroll {
4-
constructor(id, title, tags, dateLastCleaned) {
2+
constructor(id, title, tags, dateLastCleaned, catalogID, catalog) {
53
this._id = id;
6-
this._catalogItem = new CatalogItem(null, title, tags);
4+
this._catalogItem = catalog.get(catalogID);
75
this._lastCleaned = dateLastCleaned;
86
}
97

src/scroll/index.test.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
import { Scroll } from '.';
22
import { ManagedDateTime } from '../utils/date-time';
3+
import { CatalogItem } from '../catalog/item';
4+
5+
const CATALOG_ITEMS = [
6+
new CatalogItem(1, 'Regular Scroll', []),
7+
new CatalogItem(2, 'Revered Scroll', ['revered']),
8+
];
9+
10+
const catalog = { get: id => CATALOG_ITEMS.find(item => item.id === id) };
311

412
describe('Scroll', () => {
513
const lastCleaningDate = new ManagedDateTime('2021-01-01');
614

715
it('should have an id', () => {
8-
const scroll = new Scroll(1, 'Regular Scroll', []);
16+
const scroll = new Scroll(1, 'Regular Scroll', [], lastCleaningDate, 1, catalog);
917
expect(scroll.id).toBe(1);
1018
});
1119

1220
it('should have a title', () => {
13-
const scroll = new Scroll(1, 'Regular Scroll', []);
21+
const scroll = new Scroll(1, 'Regular Scroll', [], lastCleaningDate, 1, catalog);
1422
expect(scroll.title).toBe('Regular Scroll');
1523
});
1624

1725
describe('hasTag', () => {
18-
const scroll = new Scroll(1, 'Regular Scroll', ['revered']);
26+
const scroll = new Scroll(1, 'Regular Scroll', ['revered'], lastCleaningDate, 2, catalog);
1927

2028
it('should return true if the tag is present', () => {
2129
expect(scroll.hasTag('revered')).toBe(true);
@@ -28,7 +36,7 @@ describe('Scroll', () => {
2836

2937
describe('daysSinceLastCleaning', () => {
3038
it('should return the difference in days between last cleaned date and target date', () => {
31-
const scroll = new Scroll(1, 'Revered Scroll', ['revered'], lastCleaningDate);
39+
const scroll = new Scroll(2, 'Revered Scroll', ['revered'], lastCleaningDate, 2, catalog);
3240
const targetDate = new ManagedDateTime('2021-01-02');
3341
expect(scroll.daysSinceLastCleaning(targetDate)).toBe(1);
3442
});
@@ -38,7 +46,7 @@ describe('Scroll', () => {
3846
describe('revered scrolls', () => {
3947
const sixHundredAndNinetyNineDaysLater = new ManagedDateTime('2022-11-31');
4048
const sevenHundredAndOneDaysLater = new ManagedDateTime('2022-12-03');
41-
const scroll = new Scroll(1, 'Revered Scroll', ['revered'], lastCleaningDate);
49+
const scroll = new Scroll(2, 'Revered Scroll', ['revered'], lastCleaningDate, 2, catalog);
4250

4351
it('should return true if date last cleaned is greater than 700', () => {
4452
expect(scroll.needsCleaning(sevenHundredAndOneDaysLater)).toBe(true);
@@ -53,7 +61,7 @@ describe('Scroll', () => {
5361
const fourteenHundredAndNinetyNineDaysLater = new ManagedDateTime('2025-02-08');
5462
const fifteenHundredAndOneDaysLater = new ManagedDateTime('2025-02-10');
5563

56-
const scroll = new Scroll(1, 'Regular Scroll', [], lastCleaningDate);
64+
const scroll = new Scroll(1, 'Regular Scroll', [], lastCleaningDate, 1, catalog);
5765

5866
it('should return true if date last cleaned is greater than 1500', () => {
5967
expect(scroll.needsCleaning(fifteenHundredAndOneDaysLater)).toBe(true);

0 commit comments

Comments
 (0)