Skip to content

Commit b72b7be

Browse files
Update dependencies
1 parent 2e065af commit b72b7be

File tree

7 files changed

+10095
-5111
lines changed

7 files changed

+10095
-5111
lines changed

.babelrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Chess Front End Refactor & Testing Challenge
22

3-
## Setup
3+
## Setup
44

55
```bash
66
npm install
@@ -10,15 +10,15 @@ To run the test watcher, run
1010

1111
```bash
1212
npm t
13-
```
13+
```
1414

15-
---
15+
---
1616

1717
## Introduction
1818

19-
Chess has a function `getUserRating` that determines a user's rating, calculated from the user object, which has this form::
19+
Chess has a function `getUserRating` that determines a user's rating, calculated from the user object, which has this form:
2020

21-
```js
21+
```ts
2222
{
2323
username: 'chessman',
2424
yearsActive: 0,
@@ -52,11 +52,11 @@ A user's rating will start at 0 initially and will increase _or_ decrease based
5252
- -1 point per lost game
5353
- -2 points per forfeited game **UNLESS** a user has a _gold_ membership, in which they lose **0** points
5454

55-
---
55+
---
5656

5757
Based off the above criteria and the given user, this method call should return `getUserRating` a total rating of `6`.
5858

59-
```js
59+
```ts
6060
const userRating = getUserRating({
6161
username: 'chessman',
6262
yearsActive: 1, // 1 point
@@ -72,7 +72,7 @@ const userRating = getUserRating({
7272

7373
---
7474

75-
## Goals
75+
## Goals
7676

7777
During your interview, demonstrate your skills of TDD (Test Driven Development) and refactoring the by completing the following items in what you feel is the _most_ important order:
7878

babel.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
presets: [
3+
['@babel/preset-env', {targets: {node: 'current'}}],
4+
'@babel/preset-typescript',
5+
],
6+
};

index.test.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { getUserRating } from './src/index';
2+
3+
// create a user with years an an active player
4+
// games won, lost, draw
5+
const createUser = (user = {}, games = {}) => {
6+
return Object.assign({
7+
username: 'chessman',
8+
yearsActive: 0,
9+
membershipLevel: 'free', // bronze, silver, gold
10+
},
11+
user,
12+
{
13+
games: Object.assign({
14+
won: 0,
15+
lost: 0,
16+
draw: 0,
17+
forfeited: 0,
18+
}, games),
19+
});
20+
}
21+
22+
describe('getUserRating', () => {
23+
describe('Default functionality', () => {
24+
it('should return 0 if the user has no games, yearsActive, and has free membership', () => {
25+
const user = createUser();
26+
27+
expect(getUserRating(user)).toEqual(0);
28+
});
29+
});
30+
31+
describe('test score based on yearsActive', () => {
32+
it('a user should get 1 point for the first year active', () => {
33+
const user = createUser({
34+
yearsActive: 1,
35+
});
36+
37+
expect(getUserRating(user)).toEqual(1);
38+
});
39+
});
40+
41+
// membership status
42+
describe('test score based on membershipLevel', () => {
43+
it('should return 1 point for a user with a bronze membership', () => {
44+
const user = createUser({
45+
membershipLevel: 'bronze',
46+
});
47+
48+
expect(getUserRating(user)).toEqual(1);
49+
});
50+
});
51+
52+
53+
describe('test score based on games', () => {
54+
// TODO: write tests to score based on user's games
55+
});
56+
57+
// new feature
58+
it.skip('give 1 extra point per 10 games played', () => {
59+
const user = createUser({}, {
60+
won: 3, // 9 points
61+
lost: 1, // -1 point
62+
draw: 6, // + 6
63+
}); // + 1 for 10 games
64+
65+
expect(getUserRating(user)).toBe(15);
66+
});
67+
});

0 commit comments

Comments
 (0)