Skip to content

Commit

Permalink
[Lens Person] Fix typos and immutability tests (#2509)
Browse files Browse the repository at this point in the history
* Fix typos and immutability tests

* New immutability tests
  • Loading branch information
FriendlyUser1 authored Jul 24, 2024
1 parent 00685d6 commit 2efaed2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
2 changes: 1 addition & 1 deletion exercises/practice/lens-person/lens-person.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// This is only a SKELETON file for the 'Lense Person' exercise. It's been provided as a
// This is only a SKELETON file for the 'Lens Person' exercise. It's been provided as a
// convenience to get you started writing code faster.
//

Expand Down
52 changes: 23 additions & 29 deletions exercises/practice/lens-person/lens-person.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { bornAtLens, nameLens, streetLens } from './lens-person';

// test data
const person = new Person(
new Name('Saravanan', 'Lakshamanan'),
new Name('Saravanan', 'Lakshmanan'),
new Born(
new Address(100, 'Hospital street', 'Tamil Nadu', 'India'),
new Date(),
Expand All @@ -31,38 +31,36 @@ describe('nameLens', () => {
expect(nameLens.get(updatedPerson)).toEqual(updatedPerson.name);
});

xtest('should ensure immutability by checking the original person object', () => {
expect(person).not.toStrictEqual(
new Person(new Name('Sara', 'Lakshamanan'), person.born, person.address),
);
xtest('should ensure immutability when setting a new name', () => {
const originalName = new Name('Saravanan', 'Lakshmanan');
nameLens.set(person, new Name('Subhash', 'Forst'));
expect(person.name).toStrictEqual(originalName);
});
});

// Test suite for bornAtLens
describe('bornAtLens', () => {
xtest('should get the address where the person was born', () => {
xtest('should get the address for where the person was born', () => {
expect(bornAtLens.get(person)).toEqual(person.born.bornAt);
});

xtest('should set a new street for the place where the person was born', () => {
xtest('should set a new address for where the person was born', () => {
const updatedPerson = bornAtLens.set(
person,
new Address(2, 'Exercism street', 'Tamil Nadu', 'India'),
);
expect(bornAtLens.get(updatedPerson)).toEqual(updatedPerson.born.bornAt);
});

xtest('should ensure immutability by checking the original person object', () => {
expect(person).not.toEqual(
new Person(
person.name,
new Born(
new Address(2, 'Exercism street', 'Tamil Nadu', 'India'),
person.born.bornOn,
),
person.address,
),
xtest('should ensure immutability when setting a new birth address', () => {
const originalBirthAddress = new Address(
100,
'Hospital street',
'Tamil Nadu',
'India',
);
bornAtLens.set(person, new Address(15, 'Clinic street', 'Kerala', 'India'));
expect(person.born.bornAt).toStrictEqual(originalBirthAddress);
});
});

Expand All @@ -77,18 +75,14 @@ describe('streetLens', () => {
expect(streetLens.get(updatedPerson)).toEqual(updatedPerson.address.street);
});

xtest('should ensure immutability by checking the original person object', () => {
expect(person).not.toEqual(
new Person(
person.name,
person.born,
new Address(
person.address.houseNumber,
'Exercism Street',
person.address.place,
person.address.country,
),
),
xtest('should ensure immutability when setting a new street', () => {
const originalAddress = new Address(
1,
'Coder street',
'Tamil Nadu',
'India',
);
streetLens.set(person, 'Mimic street');
expect(person.address).toStrictEqual(originalAddress);
});
});

0 comments on commit 2efaed2

Please sign in to comment.