From 8bf786a9c1fb68f1164a175284258c7985290955 Mon Sep 17 00:00:00 2001 From: Sarah Reimann Date: Tue, 15 Aug 2023 14:49:50 -0700 Subject: [PATCH 1/6] test commit --- src/index.test.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/index.test.ts b/src/index.test.ts index f3b13a9..e69de29 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1,7 +0,0 @@ -//write tests here - -describe('Tests will go here!', () => { - it('should pass', () => { - expect(true).toBeTruthy() - }) -}) \ No newline at end of file From eb629ad1c16d70e6fdb4a0234b8aeb95e87b931b Mon Sep 17 00:00:00 2001 From: Sarah Reimann Date: Tue, 15 Aug 2023 14:53:37 -0700 Subject: [PATCH 2/6] WIP: in the middle of writing test for #1 --- src/index.test.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/index.test.ts b/src/index.test.ts index e69de29..4408aea 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -0,0 +1,11 @@ +//write tests here + +describe('computed properties', () => { + it('should return an object whose keys are defined by variables', () => { + + //Arrange + const expected = + + expect(true).toBeTruthy() + }) +}) \ No newline at end of file From ef46de4180899458838bd775bfa9fbc4941180f3 Mon Sep 17 00:00:00 2001 From: Sarah Reimann Date: Tue, 15 Aug 2023 16:45:13 -0700 Subject: [PATCH 3/6] write tests and stub functions --- src/index.test.ts | 247 +++++++++++++++++++++++++++++++++++++++++++++- src/index.ts | 51 +++++++++- 2 files changed, 293 insertions(+), 5 deletions(-) diff --git a/src/index.test.ts b/src/index.test.ts index 4408aea..ac2e365 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1,11 +1,250 @@ +import { computedProperties, createNewCar, newCarNewAttributes, addUser, reverseSortUsers, addUserAndId, addUserAndIdInRegularOrder } from "."; + //write tests here describe('computed properties', () => { it('should return an object whose keys are defined by variables', () => { //Arrange - const expected = + const PROP1 = "property1" + const PROP2 = "property2" + const expected = { 1: "property1", 2: "property2" }; + + //Act + const actual = computedProperties(PROP1, PROP2) + + //Assert + expect(actual).toEqual(expected); + }); +}); + +describe('create a new car object', () => { + it('should return the object that is passed to it', () => { + + //Arrange + const CAR = { make: "vw", model: "thing", value: 345 } + const expected = { make: "vw", model: "thing", value: 345 }; + + //Act + const actual = createNewCar(CAR); + + //Assert + expect(actual).toEqual(expected); + }); + + it('should return an object with different key attributes using the object passed to it', () => { + + //Arrange + const CAR = { make: "vw", model: "thing", value: 345 } + const expected = { Make: "vw", Model: "thing", Value: 345 } + + //Act + const actual = newCarNewAttributes(CAR); + + //Assert + expect(actual).toEqual(expected); + }); +}); + +describe('add a new user to the database where the new user key is equal to the id', () => { + it('it should return an immutable copy of the users object with the new user integrated into it', () => { + + //Arrange + 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" + } + } + + //Act + const actual = addUser(USERS, NEW_USER); + + //Assert + expect(actual).toEqual(expected); + }); +}); + +describe('sort users in database in reverse order', () => { + it('should output the users in reverse order of their ids', () => { + + //Arrange + 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" + } + ]; + + //Act + const actual = reverseSortUsers(USER_REPOSITORY); + + //Assert + expect(actual).toEqual(expected); + }); +}); + +describe('return immutable copy of repository where new user is added and user id is added to sort array maintaining reverse order', () => { + it('should return an immutable repository with added user into items and id into sort', () => { + + //Arrage + 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"], + } + + //Act + const actual = addUserAndId(ORIGINAL_REPOSITORY, NEW_USER) + }); +}); + +describe('return immutable copy of repository where new user is added and user id is added to sort array in regular order', () => { + it('should return an immutable repository with added user into items and id into sort', () => { + + //Arrage + 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"], + } + + //Act + const actual = addUserAndIdInRegularOrder(ORIGINAL_REPOSITORY, NEW_USER) + }); +}); - expect(true).toBeTruthy() - }) -}) \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index bb6b54e..9377c29 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1,50 @@ -//Define class here \ No newline at end of file +//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 +} + + +export const computedProperties = (prop1: string, prop2: string) => { + +} + +export const createNewCar = (car: Readonly) => { + +} + +export const newCarNewAttributes = (car: Readonly) => { + +} + +export const addUser = (users: Readonly, user: User) => { + +} + +export const reverseSortUsers = (user_repository: Readonly) => { + +} + +export const addUserAndId = (user_repository: Readonly, user: Users) => { + +} + +export const addUserAndIdInRegularOrder = (user_repository: Readonly, user: Users) => { + +} \ No newline at end of file From a74d730da7cd9014f8087e0fd6b92f0493901708 Mon Sep 17 00:00:00 2001 From: Sarah Reimann Date: Wed, 16 Aug 2023 09:59:18 -0700 Subject: [PATCH 4/6] update tests, was missing 2 asserts --- src/index.test.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/index.test.ts b/src/index.test.ts index ac2e365..b976d83 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1,4 +1,4 @@ -import { computedProperties, createNewCar, newCarNewAttributes, addUser, reverseSortUsers, addUserAndId, addUserAndIdInRegularOrder } from "."; +import { computedProperties, createNewCar, newCarNewAttributes, addUser, reverseSortUsers, addUserAndId, addUserAndIdInRegularOrder } from "./index"; //write tests here @@ -188,6 +188,9 @@ describe('return immutable copy of repository where new user is added and user i //Act const actual = addUserAndId(ORIGINAL_REPOSITORY, NEW_USER) + + //Assert + expect(actual).toEqual(expected); }); }); @@ -245,6 +248,9 @@ describe('return immutable copy of repository where new user is added and user i //Act const actual = addUserAndIdInRegularOrder(ORIGINAL_REPOSITORY, NEW_USER) + + //Assert + expect(actual).toEqual(expected); }); }); From 4941b49f9702d6e697a9fb59a170b7f6069be73c Mon Sep 17 00:00:00 2001 From: Sarah Reimann Date: Wed, 16 Aug 2023 14:57:03 -0700 Subject: [PATCH 5/6] improve readbility, remove comments --- src/index.test.ts | 81 +++++++++++++++++++---------------------------- src/index.ts | 5 --- 2 files changed, 32 insertions(+), 54 deletions(-) diff --git a/src/index.test.ts b/src/index.test.ts index b976d83..544440e 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1,56 +1,50 @@ -import { computedProperties, createNewCar, newCarNewAttributes, addUser, reverseSortUsers, addUserAndId, addUserAndIdInRegularOrder } from "./index"; - -//write tests here - -describe('computed properties', () => { +import { + computedProperties, + createNewCar, + addUser, + reverseSortUsers, + addUserAndId, + addUserAndIdInRegularOrder } from "./index"; + +describe('computedProperties', () => { it('should return an object whose keys are defined by variables', () => { - //Arrange - const PROP1 = "property1" - const PROP2 = "property2" + const prop1 = "property1" + const prop2 = "property2" const expected = { 1: "property1", 2: "property2" }; - //Act - const actual = computedProperties(PROP1, PROP2) + const actual = computedProperties(prop1, prop2) - //Assert expect(actual).toEqual(expected); }); }); -describe('create a new car object', () => { +describe('createNewCar', () => { it('should return the object that is passed to it', () => { - //Arrange - const CAR = { make: "vw", model: "thing", value: 345 } + const car = { make: "vw", model: "thing", value: 345 } const expected = { make: "vw", model: "thing", value: 345 }; - //Act - const actual = createNewCar(CAR); + const actual = createNewCar(car); - //Assert expect(actual).toEqual(expected); }); it('should return an object with different key attributes using the object passed to it', () => { - //Arrange - const CAR = { make: "vw", model: "thing", value: 345 } + const car = { make: "vw", model: "thing", value: 345 } const expected = { Make: "vw", Model: "thing", Value: 345 } - //Act - const actual = newCarNewAttributes(CAR); + const actual = createNewCar(car); - //Assert expect(actual).toEqual(expected); }); }); -describe('add a new user to the database where the new user key is equal to the id', () => { +describe('addUser', () => { it('it should return an immutable copy of the users object with the new user integrated into it', () => { - //Arrange - const USERS = { + const users = { "123": { "id": "123", "name": "Aron" @@ -61,7 +55,7 @@ describe('add a new user to the database where the new user key is equal to the } } - const NEW_USER = { + const new_user = { "id": "789", "name": "Scott" } @@ -81,19 +75,16 @@ describe('add a new user to the database where the new user key is equal to the } } - //Act - const actual = addUser(USERS, NEW_USER); + const actual = addUser(users, new_user); - //Assert expect(actual).toEqual(expected); }); }); -describe('sort users in database in reverse order', () => { +describe('reverseSortUsers', () => { it('should output the users in reverse order of their ids', () => { - //Arrange - const USER_REPOSITORY = { + const user_repository = { items: { "123": { "id": "123", @@ -126,19 +117,16 @@ describe('sort users in database in reverse order', () => { } ]; - //Act - const actual = reverseSortUsers(USER_REPOSITORY); + const actual = reverseSortUsers(user_repository); - //Assert expect(actual).toEqual(expected); }); }); -describe('return immutable copy of repository where new user is added and user id is added to sort array maintaining reverse order', () => { +describe('addUserAndId', () => { it('should return an immutable repository with added user into items and id into sort', () => { - //Arrage - const ORIGINAL_REPOSITORY = + const original_repository = { items: { "A": { @@ -157,7 +145,7 @@ describe('return immutable copy of repository where new user is added and user i sort: ["C", "B", "A"], } - const NEW_USER = { + const new_user = { "D": { "id": "D", "name": "Katlin" @@ -186,19 +174,16 @@ describe('return immutable copy of repository where new user is added and user i sort: ["D", "C", "B", "A"], } - //Act - const actual = addUserAndId(ORIGINAL_REPOSITORY, NEW_USER) + const actual = addUserAndId(original_repository, new_user) - //Assert expect(actual).toEqual(expected); }); }); -describe('return immutable copy of repository where new user is added and user id is added to sort array in regular order', () => { +describe('addUserAndIdInRegularOrder', () => { it('should return an immutable repository with added user into items and id into sort', () => { - //Arrage - const ORIGINAL_REPOSITORY = + const original_repository = { items: { "A": { @@ -217,7 +202,7 @@ describe('return immutable copy of repository where new user is added and user i sort: ["A", "B", "C"], } - const NEW_USER = { + const new_user = { "D": { "id": "D", "name": "Katlin" @@ -246,10 +231,8 @@ describe('return immutable copy of repository where new user is added and user i sort: ["A", "B", "C", "D"], } - //Act - const actual = addUserAndIdInRegularOrder(ORIGINAL_REPOSITORY, NEW_USER) + const actual = addUserAndIdInRegularOrder(original_repository, new_user) - //Assert expect(actual).toEqual(expected); }); }); diff --git a/src/index.ts b/src/index.ts index 9377c29..f270d06 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,11 +28,6 @@ export const computedProperties = (prop1: string, prop2: string) => { export const createNewCar = (car: Readonly) => { } - -export const newCarNewAttributes = (car: Readonly) => { - -} - export const addUser = (users: Readonly, user: User) => { } From 5b590ee9fc77308065aa3ca33e9932b6de25e8b3 Mon Sep 17 00:00:00 2001 From: Sarah Reimann Date: Wed, 16 Aug 2023 15:27:40 -0700 Subject: [PATCH 6/6] update test --- src/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.test.ts b/src/index.test.ts index 544440e..19bf60a 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -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)