Skip to content

Sarah tdd lesson 2 green phase #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: sarah-tdd-lesson-2-red-phase
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('computedProperties', () => {

const prop1 = "property1"
const prop2 = "property2"
const expected = { 1: "property1", 2: "property2" };
const expected = { "property1": "panda", "property2": "salad" };

const actual = computedProperties(prop1, prop2)

Expand All @@ -20,16 +20,6 @@ describe('computedProperties', () => {
});

describe('createNewCar', () => {
it('should return the object that is passed to it', () => {

const car = { make: "vw", model: "thing", value: 345 }
const expected = { make: "vw", model: "thing", value: 345 };

const actual = createNewCar(car);

expect(actual).toEqual(expected);
});

it('should return an object with different key attributes using the object passed to it', () => {

const car = { make: "vw", model: "thing", value: 345 }
Expand Down Expand Up @@ -146,10 +136,8 @@ describe('addUserAndId', () => {
}

const new_user = {
"D": {
"id": "D",
"name": "Katlin"
}
};

const expected = {
Expand Down Expand Up @@ -203,11 +191,9 @@ describe('addUserAndIdInRegularOrder', () => {
}

const new_user = {
"D": {
"id": "D",
"name": "Katlin"
}
};
"id": "D",
"name": "Katlin"
};

const expected = {
items: {
Expand Down
56 changes: 46 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,66 @@ export interface Users {
}

export interface User_Repository {
readonly items: object,
readonly sort: Array<string>
readonly items: Record<string, User>,
readonly sort: string[];
}


export const computedProperties = (prop1: string, prop2: string) => {

export const computedProperties = (prop1: string, prop2: string) => {
const obj = {
[prop1]: "panda",
[prop2]: "salad"
}
return obj;
}

export const createNewCar = (car: Readonly<Car>) => {
const {make: Make, model: Model, value: Value} = car;
return {
Make,
Model,
Value}
}

}
export const addUser = (users: Readonly<Users>, user: User) => {

return {
...users,
[user.id]: user
}
}

export const reverseSortUsers = (user_repository: Readonly<User_Repository>) => {

const array = user_repository.sort.map(id => {
return (
user_repository.items[id]
)
}
)
return array;
}

export const addUserAndId = (user_repository: Readonly<User_Repository>, user: Users) => {

export const addUserAndId = (user_repository: Readonly<User_Repository>, user: User) => {
console.log(user);
return {
items: {
...user_repository.items,
[user.id]: user
},
sort: [user.id, ...user_repository.sort],
}
}

export const addUserAndIdInRegularOrder = (user_repository: Readonly<User_Repository>, user: Users) => {

export const addUserAndIdInRegularOrder = (user_repository: Readonly<User_Repository>, user: User) => {
const users = {
...user_repository.items,
[user.id]: user
}
const sort = Object.keys(users).map(id => {
return id
})
return {
items: users,
sort: sort
}
}