Skip to content

Commit 038f96f

Browse files
committed
setup initial examples + tests + CI
1 parent 0cfac45 commit 038f96f

File tree

4 files changed

+62
-31
lines changed

4 files changed

+62
-31
lines changed

README.md

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,7 @@
1-
[![Continuous Integration](https://github.com/kaiosilveira/refactoring-catalog-template/actions/workflows/ci.yml/badge.svg)](https://github.com/kaiosilveira/refactoring-catalog-template/actions/workflows/ci.yml)
1+
[![Continuous Integration](https://github.com/kaiosilveira/replace-function-with-command-refactoring/actions/workflows/ci.yml/badge.svg)](https://github.com/kaiosilveira/replace-function-with-command-refactoring/actions/workflows/ci.yml)
22

33
# Refactoring catalog repository template
44

5-
This is a quick template to help me get a new refactoring repo going.
6-
7-
## Things to do after creating a repo off of this template
8-
9-
1. Run `GITHUB_TOKEN=$(gh auth token) yarn tools:cli prepare-repository -r <repo_name>`. It will:
10-
11-
- Update the `README.md` file with the actual repository name, CI badge, and commit history link
12-
- Update `package.json` with the repository's name and remote URL
13-
- Update the repo's homepage on GitHub with:
14-
- A description
15-
- A website link to https://github.com/kaiosilveira/refactoring
16-
- The following labels: javascript, refactoring, [REPOSITORY_NAME]
17-
18-
2. Replace the lorem ipsum text sections below with actual text
19-
205
## Useful commands
216

227
- Generate markdown containing a diff with patch information based on a range of commits:
@@ -28,7 +13,7 @@ yarn tools:cli generate-diff -f <first_commit_sha> -l <last_commit_sha>
2813
- To generate the commit history table for the last section, including the correct links:
2914

3015
```bash
31-
yarn tools:cli generate-cmt-table -r [REPOSITORY_NAME]
16+
yarn tools:cli generate-cmt-table -r replace-function-with-command-refactoring
3217
```
3318

3419
---
@@ -37,7 +22,7 @@ yarn tools:cli generate-cmt-table -r [REPOSITORY_NAME]
3722

3823
---
3924

40-
# Refactoring name
25+
# Replace Function With Command
4126

4227
**Formerly: Old name**
4328

@@ -121,8 +106,8 @@ Below there's the commit history for the steps detailed above.
121106

122107
| Commit SHA | Message |
123108
| --------------------------------------------------------------------------- | ------------------------ |
124-
| [cmt-sha-1](https://github.com/kaiosilveira/[REPOSITORY_NAME]/commit-SHA-1) | description of commit #1 |
125-
| [cmt-sha-2](https://github.com/kaiosilveira/[REPOSITORY_NAME]/commit-SHA-2) | description of commit #2 |
126-
| [cmt-sha-n](https://github.com/kaiosilveira/[REPOSITORY_NAME]/commit-SHA-n) | description of commit #n |
109+
| [cmt-sha-1](https://github.com/kaiosilveira/replace-function-with-command-refactoring/commit-SHA-1) | description of commit #1 |
110+
| [cmt-sha-2](https://github.com/kaiosilveira/replace-function-with-command-refactoring/commit-SHA-2) | description of commit #2 |
111+
| [cmt-sha-n](https://github.com/kaiosilveira/replace-function-with-command-refactoring/commit-SHA-n) | description of commit #n |
127112

128-
For the full commit history for this project, check the [Commit History tab](https://github.com/kaiosilveira/[REPOSITORY_NAME]/commits/main).
113+
For the full commit history for this project, check the [Commit History tab](https://github.com/kaiosilveira/replace-function-with-command-refactoring/commits/main).

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"type": "module",
3-
"name": "refactoring-catalog-template",
3+
"name": "replace-function-with-command-refactoring",
44
"version": "1.0.0",
55
"main": "index.js",
6-
"repository": "https://github.com/kaiosilveira/refactoring-catalog-template.git",
6+
"repository": "https://github.com/kaiosilveira/replace-function-with-command-refactoring.git",
77
"author": "Kaio Silveira <silveira.kaio@icloud.com>",
88
"license": "MIT",
99
"scripts": {
@@ -14,4 +14,4 @@
1414
"jest": "^29.0.3",
1515
"@kaiosilveira/refactoring-catalog-cli": "0.7.34"
1616
}
17-
}
17+
}

src/index.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1-
export function toBeRefactored() {
2-
return 'Hello, world!';
1+
export function score(candidate, medicalExam, scoringGuide) {
2+
let result = 0;
3+
let healthLevel = 0;
4+
let highMedicalRiskFlag = false;
5+
6+
if (medicalExam.isSmoker) {
7+
healthLevel += 10;
8+
highMedicalRiskFlag = true;
9+
}
10+
11+
let certificationGrade = 'regular';
12+
if (scoringGuide.stateWithLowCertification(candidate.originState)) {
13+
certificationGrade = 'low';
14+
result -= 5;
15+
}
16+
17+
// lots more code like this
18+
result -= Math.max(healthLevel - 5, 0);
19+
20+
return result;
321
}

src/index.test.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
1-
import { toBeRefactored } from './index';
1+
import { score } from './index';
22

3-
describe('functionToBeRefactored', () => {
4-
it('should work', () => {
5-
expect(toBeRefactored()).toEqual('Hello, world!');
3+
describe('score', () => {
4+
it('should return 0 if candidate is not a smoker and has a regular certification grade', () => {
5+
const candidate = { originState: 'FL' };
6+
const medicalExam = { isSmoker: false };
7+
const scoringGuide = { stateWithLowCertification: () => false };
8+
9+
expect(score(candidate, medicalExam, scoringGuide)).toBe(0);
10+
});
11+
12+
it('should return -5 if candidate is not a smoker and has a low certification grade', () => {
13+
const candidate = { originState: 'FL' };
14+
const medicalExam = { isSmoker: false };
15+
const scoringGuide = { stateWithLowCertification: () => true };
16+
17+
expect(score(candidate, medicalExam, scoringGuide)).toBe(-5);
18+
});
19+
20+
it('should return -5 if candidate is a smoker and has a regular certification grade', () => {
21+
const candidate = { originState: 'FL' };
22+
const medicalExam = { isSmoker: true };
23+
const scoringGuide = { stateWithLowCertification: () => false };
24+
25+
expect(score(candidate, medicalExam, scoringGuide)).toBe(-5);
26+
});
27+
28+
it('should return -10 if candidate is a smoker and has a low certification grade', () => {
29+
const candidate = { originState: 'FL' };
30+
const medicalExam = { isSmoker: true };
31+
const scoringGuide = { stateWithLowCertification: () => true };
32+
33+
expect(score(candidate, medicalExam, scoringGuide)).toBe(-10);
634
});
735
});

0 commit comments

Comments
 (0)