Skip to content

Commit 20b234e

Browse files
committed
move scoringGuide to Score's constructor
1 parent 091533c commit 20b234e

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
export function score(candidate, medicalExam, scoringGuide) {
2-
return new Scorer(candidate, medicalExam).execute(scoringGuide);
2+
return new Scorer(candidate, medicalExam, scoringGuide).execute();
33
}
44

55
export class Scorer {
6-
constructor(candidate, medicalExam) {
6+
constructor(candidate, medicalExam, scoringGuide) {
77
this._candidate = candidate;
88
this._medicalExam = medicalExam;
9+
this._scoringGuide = scoringGuide;
910
}
1011

11-
execute(scoringGuide) {
12+
execute() {
1213
let result = 0;
1314
let healthLevel = 0;
1415
let highMedicalRiskFlag = false;
@@ -19,7 +20,7 @@ export class Scorer {
1920
}
2021

2122
let certificationGrade = 'regular';
22-
if (scoringGuide.stateWithLowCertification(this._candidate.originState)) {
23+
if (this._scoringGuide.stateWithLowCertification(this._candidate.originState)) {
2324
certificationGrade = 'low';
2425
result -= 5;
2526
}

src/index.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,34 @@ describe('Scorer', () => {
4040
const medicalExam = { isSmoker: false };
4141
const scoringGuide = { stateWithLowCertification: () => false };
4242

43-
const scorer = new Scorer(candidate, medicalExam);
44-
expect(scorer.execute(scoringGuide)).toBe(0);
43+
const scorer = new Scorer(candidate, medicalExam, scoringGuide);
44+
expect(scorer.execute()).toBe(0);
4545
});
4646

4747
it('should return -5 if candidate is not a smoker and has a low certification grade', () => {
4848
const candidate = { originState: 'FL' };
4949
const medicalExam = { isSmoker: false };
5050
const scoringGuide = { stateWithLowCertification: () => true };
5151

52-
const scorer = new Scorer(candidate, medicalExam);
53-
expect(scorer.execute(scoringGuide)).toBe(-5);
52+
const scorer = new Scorer(candidate, medicalExam, scoringGuide);
53+
expect(scorer.execute()).toBe(-5);
5454
});
5555

5656
it('should return -5 if candidate is a smoker and has a regular certification grade', () => {
5757
const candidate = { originState: 'FL' };
5858
const medicalExam = { isSmoker: true };
5959
const scoringGuide = { stateWithLowCertification: () => false };
6060

61-
const scorer = new Scorer(candidate, medicalExam);
62-
expect(scorer.execute(scoringGuide)).toBe(-5);
61+
const scorer = new Scorer(candidate, medicalExam, scoringGuide);
62+
expect(scorer.execute()).toBe(-5);
6363
});
6464

6565
it('should return -10 if candidate is a smoker and has a low certification grade', () => {
6666
const candidate = { originState: 'FL' };
6767
const medicalExam = { isSmoker: true };
6868
const scoringGuide = { stateWithLowCertification: () => true };
6969

70-
const scorer = new Scorer(candidate, medicalExam);
71-
expect(scorer.execute(scoringGuide)).toBe(-10);
70+
const scorer = new Scorer(candidate, medicalExam, scoringGuide);
71+
expect(scorer.execute()).toBe(-10);
7272
});
7373
});

0 commit comments

Comments
 (0)