Skip to content

Sarah tdd lesson 2 red phase #51

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 6 commits into
base: sarah-tdd-workshop
Choose a base branch
from
Open
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
244 changes: 238 additions & 6 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,239 @@
//write tests here
import {
computedProperties,
createNewCar,
addUser,
reverseSortUsers,
addUserAndId,
addUserAndIdInRegularOrder } from "./index";

describe('computedProperties', () => {
it('should return an object whose keys are defined by variables', () => {

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

const actual = computedProperties(prop1, prop2)

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

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 }
const expected = { Make: "vw", Model: "thing", Value: 345 }

const actual = createNewCar(car);

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

describe('addUser', () => {
it('it should return an immutable copy of the users object with the new user integrated into it', () => {

const users = {
"123": {
"id": "123",
"name": "Aron"
},
"456": {
"id": "456",
"name": "Stormi"
}
}

const new_user = {
"id": "789",
"name": "Scott"
}

const expected = {
"123": {
"id": "123",
"name": "Aron"
},
"456": {
"id": "456",
"name": "Stormi"
},
"789": {
"id": "789",
"name": "Scott"
}
}

const actual = addUser(users, new_user);

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

describe('reverseSortUsers', () => {
it('should output the users in reverse order of their ids', () => {

const user_repository = {
items: {
"123": {
"id": "123",
"name": "Aron"
},
"456": {
"id": "456",
"name": "Stormi"
},
"789": {
"id": "789",
"name": "Scott"
}
},
sort: ["789", "456", "123"],
};

const expected = [
{
"id": "789",
"name": "Scott"
},
{
"id": "456",
"name": "Stormi"
},
{
"id": "123",
"name": "Aron"
}
];

const actual = reverseSortUsers(user_repository);

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

describe('addUserAndId', () => {
it('should return an immutable repository with added user into items and id into sort', () => {

const original_repository =
{
items: {
"A": {
"id": "A",
"name": "Aron"
},
"B": {
"id": "B",
"name": "Stormi"
},
"C": {
"id": "C",
"name": "Scott"
}
},
sort: ["C", "B", "A"],
}

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

const expected = {
items: {
"A": {
"id": "A",
"name": "Aron"
},
"B": {
"id": "B",
"name": "Stormi"
},
"C": {
"id": "C",
"name": "Scott"
},
"D": {
"id": "D",
"name": "Katlin"
}
},
sort: ["D", "C", "B", "A"],
}

const actual = addUserAndId(original_repository, new_user)

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

describe('addUserAndIdInRegularOrder', () => {
it('should return an immutable repository with added user into items and id into sort', () => {

const original_repository =
{
items: {
"A": {
"id": "A",
"name": "Aron"
},
"B": {
"id": "B",
"name": "Stormi"
},
"C": {
"id": "C",
"name": "Scott"
}
},
sort: ["A", "B", "C"],
}

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

const expected = {
items: {
"A": {
"id": "A",
"name": "Aron"
},
"B": {
"id": "B",
"name": "Stormi"
},
"C": {
"id": "C",
"name": "Scott"
},
"D": {
"id": "D",
"name": "Katlin"
}
},
sort: ["A", "B", "C", "D"],
}

const actual = addUserAndIdInRegularOrder(original_repository, new_user)

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

describe('Tests will go here!', () => {
it('should pass', () => {
expect(true).toBeTruthy()
})
})
46 changes: 45 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
//Define class here
//Define class here

export interface Car {
readonly make: string,
readonly model: string,
readonly value: number
}

export interface User {
readonly id: string,
readonly name: string
}

export interface Users {
readonly [userID: string]: User
}

export interface User_Repository {
readonly items: object,
readonly sort: Array<string>
}


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

}

export const createNewCar = (car: Readonly<Car>) => {

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

}

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

}

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

}

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

}