diff --git a/Client/reasn-client/packages/common/__tests__/models/AddressDto.test.ts b/Client/reasn-client/packages/common/__tests__/models/AddressDto.test.ts index 88d8eb4e..edcc9338 100644 --- a/Client/reasn-client/packages/common/__tests__/models/AddressDto.test.ts +++ b/Client/reasn-client/packages/common/__tests__/models/AddressDto.test.ts @@ -1,4 +1,4 @@ -import { AddressDto } from '@reasn/common/models/AddressDto' +import { AddressDtoMapper, AddressDto } from '@reasn/common/models/AddressDto' import ModelMappingError from '@reasn/common/errors/ModelMappingError' describe('AddressDto', () => { @@ -8,19 +8,6 @@ describe('AddressDto', () => { const state = 'Test State' const zipCode = '12345' - describe('constructor', () => { - it('should create an instance of AddressDto', () => { - const address = new AddressDto(country, city, street, state, zipCode) - - expect(address).toBeInstanceOf(AddressDto) - expect(address.Country).toBe(country) - expect(address.City).toBe(city) - expect(address.Street).toBe(street) - expect(address.State).toBe(state) - expect(address.ZipCode).toBe(zipCode) - }) - }) - describe('fromJson', () => { it('should create an instance of AddressDto from JSON string', () => { const json = `{ @@ -31,9 +18,7 @@ describe('AddressDto', () => { "ZipCode": "${zipCode}" }` - let address = AddressDto.fromJson(json) - - expect(address).toBeInstanceOf(AddressDto) + let address = AddressDtoMapper.fromJSON(json) address = address as AddressDto expect(address.Country).toBe(country) @@ -43,12 +28,8 @@ describe('AddressDto', () => { expect(address.ZipCode).toBe(zipCode) }) - it('should return null if the JSON string is empty', () => { - const json = '' - - const address = AddressDto.fromJson(json) - - expect(address).toBeNull() + it('should throw error if the JSON string is empty', () => { + expect(() => AddressDtoMapper.fromJSON('')).toThrow(ModelMappingError) }) it('should throw an error when providing JSON without each property individually', () => { @@ -87,15 +68,11 @@ describe('AddressDto', () => { "State": "${state}" }` - expect(() => AddressDto.fromJson(jsonWithoutCountry)).toThrow(ModelMappingError) - expect(() => AddressDto.fromJson(jsonWithoutCity)).toThrow(ModelMappingError) - expect(() => AddressDto.fromJson(jsonWithoutStreet)).toThrow(ModelMappingError) - expect(() => AddressDto.fromJson(jsonWithoutState)).toThrow(ModelMappingError) - - let addressWithoutZipcode = AddressDto.fromJson(jsonWithoutZipCode) - expect(addressWithoutZipcode).toBeInstanceOf(AddressDto) - addressWithoutZipcode = addressWithoutZipcode as AddressDto - expect(addressWithoutZipcode.ZipCode).toBeNull() + expect(() => AddressDtoMapper.fromJSON(jsonWithoutCountry)).toThrow(ModelMappingError) + expect(() => AddressDtoMapper.fromJSON(jsonWithoutCity)).toThrow(ModelMappingError) + expect(() => AddressDtoMapper.fromJSON(jsonWithoutStreet)).toThrow(ModelMappingError) + expect(() => AddressDtoMapper.fromJSON(jsonWithoutState)).toThrow(ModelMappingError) + expect(() => AddressDtoMapper.fromJSON(jsonWithoutZipCode)).toThrow(ModelMappingError) }) }) @@ -109,9 +86,7 @@ describe('AddressDto', () => { ZipCode: zipCode } - let address = AddressDto.fromObject(object) - - expect(address).toBeInstanceOf(AddressDto) + let address = AddressDtoMapper.fromObject(object) address = address as AddressDto expect(address.Country).toBe(country) @@ -165,16 +140,12 @@ describe('AddressDto', () => { State: state } - expect(() => AddressDto.fromObject(object)).toThrow(ModelMappingError) - expect(() => AddressDto.fromObject(objectWithoutCountry)).toThrow(ModelMappingError) - expect(() => AddressDto.fromObject(objectWithoutCity)).toThrow(ModelMappingError) - expect(() => AddressDto.fromObject(objectWithoutStreet)).toThrow(ModelMappingError) - expect(() => AddressDto.fromObject(objectWithoutState)).toThrow(ModelMappingError) - - let addressWithoutZipcode = AddressDto.fromObject(objectWithoutZipCode) - expect(addressWithoutZipcode).toBeInstanceOf(AddressDto) - addressWithoutZipcode = addressWithoutZipcode as AddressDto - expect(addressWithoutZipcode.ZipCode).toBeNull() + expect(() => AddressDtoMapper.fromObject(object)).toThrow(ModelMappingError) + expect(() => AddressDtoMapper.fromObject(objectWithoutCountry)).toThrow(ModelMappingError) + expect(() => AddressDtoMapper.fromObject(objectWithoutCity)).toThrow(ModelMappingError) + expect(() => AddressDtoMapper.fromObject(objectWithoutStreet)).toThrow(ModelMappingError) + expect(() => AddressDtoMapper.fromObject(objectWithoutState)).toThrow(ModelMappingError) + expect(() => AddressDtoMapper.fromObject(objectWithoutZipCode)).toThrow(ModelMappingError) }) }) }) \ No newline at end of file diff --git a/Client/reasn-client/packages/common/__tests__/models/CommentDto.test.ts b/Client/reasn-client/packages/common/__tests__/models/CommentDto.test.ts index cd0ae0c3..520db658 100644 --- a/Client/reasn-client/packages/common/__tests__/models/CommentDto.test.ts +++ b/Client/reasn-client/packages/common/__tests__/models/CommentDto.test.ts @@ -1,5 +1,5 @@ import ModelMappingError from '@reasn/common/errors/ModelMappingError' -import { CommentDto } from '@reasn/common/models/CommentDto' +import { CommentDto, CommentDtoMapper } from '@reasn/common/models/CommentDto' describe('CommentDto', () => { const eventId = 1 @@ -7,18 +7,6 @@ describe('CommentDto', () => { const createdAt = new Date() const userId = 2 - describe('constructor', () => { - it('should create an instance of CommentDto', () => { - const comment = new CommentDto(eventId, content, createdAt, userId) - - expect(comment).toBeInstanceOf(CommentDto) - expect(comment.EventId).toBe(eventId) - expect(comment.Content).toBe(content) - expect(comment.CreatedAt).toBe(createdAt) - expect(comment.UserId).toBe(userId) - }) - }) - describe('fromJson', () => { it('should create an instance of CommentDto from JSON string', () => { const json = `{ @@ -28,9 +16,7 @@ describe('CommentDto', () => { "UserId": ${userId} }` - let comment = CommentDto.fromJson(json) - - expect(comment).toBeInstanceOf(CommentDto) + let comment = CommentDtoMapper.fromJSON(json) comment = comment as CommentDto expect(comment.EventId).toBe(eventId) @@ -39,12 +25,8 @@ describe('CommentDto', () => { expect(comment.UserId).toBe(userId) }) - it('should return null if the JSON string is empty', () => { - const json = '' - - const comment = CommentDto.fromJson(json) - - expect(comment).toBeNull() + it('should throw an error if the JSON string is empty', () => { + expect(() => CommentDtoMapper.fromJSON('')).toThrow(ModelMappingError) }) it('should throw an error when providing JSON without each property individually', () => { @@ -72,10 +54,10 @@ describe('CommentDto', () => { "CreatedAt": "${createdAt.toISOString()}" }` - expect(() => CommentDto.fromJson(jsonWithoutEventId)).toThrow(ModelMappingError) - expect(() => CommentDto.fromJson(jsonWithoutContent)).toThrow(ModelMappingError) - expect(() => CommentDto.fromJson(jsonWithoutCreatedAt)).toThrow(ModelMappingError) - expect(() => CommentDto.fromJson(jsonWithoutUserId)).toThrow(ModelMappingError) + expect(() => CommentDtoMapper.fromJSON(jsonWithoutEventId)).toThrow(ModelMappingError) + expect(() => CommentDtoMapper.fromJSON(jsonWithoutContent)).toThrow(ModelMappingError) + expect(() => CommentDtoMapper.fromJSON(jsonWithoutCreatedAt)).toThrow(ModelMappingError) + expect(() => CommentDtoMapper.fromJSON(jsonWithoutUserId)).toThrow(ModelMappingError) }) }) @@ -88,9 +70,7 @@ describe('CommentDto', () => { UserId: userId } - let comment = CommentDto.fromObject(object) - - expect(comment).toBeInstanceOf(CommentDto) + let comment = CommentDtoMapper.fromObject(object) comment = comment as CommentDto expect(comment.EventId).toBe(eventId) @@ -131,11 +111,11 @@ describe('CommentDto', () => { CreatedAt: createdAt } - expect(() => CommentDto.fromObject(object)).toThrow(ModelMappingError) - expect(() => CommentDto.fromObject(objectWithoutEventId)).toThrow(ModelMappingError) - expect(() => CommentDto.fromObject(objectWithoutContent)).toThrow(ModelMappingError) - expect(() => CommentDto.fromObject(objectWithoutCreatedAt)).toThrow(ModelMappingError) - expect(() => CommentDto.fromObject(objectWithoutUserId)).toThrow(ModelMappingError) + expect(() => CommentDtoMapper.fromObject(object)).toThrow(ModelMappingError) + expect(() => CommentDtoMapper.fromObject(objectWithoutEventId)).toThrow(ModelMappingError) + expect(() => CommentDtoMapper.fromObject(objectWithoutContent)).toThrow(ModelMappingError) + expect(() => CommentDtoMapper.fromObject(objectWithoutCreatedAt)).toThrow(ModelMappingError) + expect(() => CommentDtoMapper.fromObject(objectWithoutUserId)).toThrow(ModelMappingError) }) }) }) \ No newline at end of file diff --git a/Client/reasn-client/packages/common/__tests__/models/EventDto.test.ts b/Client/reasn-client/packages/common/__tests__/models/EventDto.test.ts index e4f456af..60d77b3a 100644 --- a/Client/reasn-client/packages/common/__tests__/models/EventDto.test.ts +++ b/Client/reasn-client/packages/common/__tests__/models/EventDto.test.ts @@ -1,4 +1,4 @@ -import { EventDto } from '@reasn/common/models/EventDto' +import { EventDto, EventDtoMapper } from '@reasn/common/models/EventDto' import ModelMappingError from '@reasn/common/errors/ModelMappingError' import { TagDto } from '@reasn/common/models/TagDto' @@ -15,37 +15,6 @@ describe('EventDto', () => { const statusId = 1 const tags: TagDto[] = [{ Name: 'Tag 1' }, { Name: 'Tag 2' }] - describe('constructor', () => { - it('should create an instance of EventDto', () => { - const event = new EventDto( - name, - addressId, - description, - organizerId, - startAt, - endAt, - createdAt, - updatedAt, - slug, - statusId, - tags - ) - - expect(event).toBeInstanceOf(EventDto) - expect(event.Name).toBe(name) - expect(event.AddressId).toBe(addressId) - expect(event.Description).toBe(description) - expect(event.OrganizerId).toBe(organizerId) - expect(event.StartAt).toBe(startAt) - expect(event.EndAt).toBe(endAt) - expect(event.CreatedAt).toBe(createdAt) - expect(event.UpdatedAt).toBe(updatedAt) - expect(event.Slug).toBe(slug) - expect(event.StatusId).toBe(statusId) - expect(event.Tags).toBe(tags) - }) - }) - describe('fromJson', () => { it('should create an instance of EventDto from JSON string', () => { const json = `{ @@ -62,9 +31,7 @@ describe('EventDto', () => { "Tags": ${JSON.stringify(tags)} }` - let event = EventDto.fromJson(json) - - expect(event).toBeInstanceOf(EventDto) + let event = EventDtoMapper.fromJSON(json) event = event as EventDto expect(event.Name).toBe(name) @@ -81,11 +48,7 @@ describe('EventDto', () => { }) it('should return null if the JSON string is empty', () => { - const json = '' - - const event = EventDto.fromJson(json) - - expect(event).toBeNull() + expect(() => EventDtoMapper.fromJSON('')).toThrow(ModelMappingError) }) it('should throw an error when providing json without each property individually', () => { @@ -233,37 +196,37 @@ describe('EventDto', () => { }` expect(() => { - EventDto.fromJson(jsonWithoutName) + EventDtoMapper.fromJSON(jsonWithoutName) }).toThrow(ModelMappingError) expect(() => { - EventDto.fromJson(jsonWithoutAddressId) + EventDtoMapper.fromJSON(jsonWithoutAddressId) }).toThrow(ModelMappingError) expect(() => { - EventDto.fromJson(jsonWithoutDescription) + EventDtoMapper.fromJSON(jsonWithoutDescription) }).toThrow(ModelMappingError) expect(() => { - EventDto.fromJson(jsonWithoutOrganizerId) + EventDtoMapper.fromJSON(jsonWithoutOrganizerId) }).toThrow(ModelMappingError) expect(() => { - EventDto.fromJson(jsonWithoutStartAt) + EventDtoMapper.fromJSON(jsonWithoutStartAt) }).toThrow(ModelMappingError) expect(() => { - EventDto.fromJson(jsonWithoutEndAt) + EventDtoMapper.fromJSON(jsonWithoutEndAt) }).toThrow(ModelMappingError) expect(() => { - EventDto.fromJson(jsonWithoutCreatedAt) + EventDtoMapper.fromJSON(jsonWithoutCreatedAt) }).toThrow(ModelMappingError) expect(() => { - EventDto.fromJson(jsonWithoutUpdatedAt) + EventDtoMapper.fromJSON(jsonWithoutUpdatedAt) }).toThrow(ModelMappingError) expect(() => { - EventDto.fromJson(jsonWithoutSlug) + EventDtoMapper.fromJSON(jsonWithoutSlug) }).toThrow(ModelMappingError) expect(() => { - EventDto.fromJson(jsonWithoutStatusId) + EventDtoMapper.fromJSON(jsonWithoutStatusId) }).toThrow(ModelMappingError) expect(() => { - EventDto.fromJson(jsonWithoutTags) + EventDtoMapper.fromJSON(jsonWithoutTags) }).toThrow(ModelMappingError) }) }) @@ -284,9 +247,7 @@ describe('EventDto', () => { Tags: tags } - let event = EventDto.fromObject(obj) - - expect(event).toBeInstanceOf(EventDto) + let event = EventDtoMapper.fromObject(obj) event = event as EventDto expect(event.Name).toBe(name) @@ -461,40 +422,40 @@ describe('EventDto', () => { } expect(() => { - EventDto.fromObject(invalidObj) + EventDtoMapper.fromObject(invalidObj) }).toThrow(ModelMappingError) expect(() => { - EventDto.fromObject(objWithoutName) + EventDtoMapper.fromObject(objWithoutName) }).toThrow(ModelMappingError) expect(() => { - EventDto.fromObject(objWithoutAddressId) + EventDtoMapper.fromObject(objWithoutAddressId) }).toThrow(ModelMappingError) expect(() => { - EventDto.fromObject(objWithoutDescription) + EventDtoMapper.fromObject(objWithoutDescription) }).toThrow(ModelMappingError) expect(() => { - EventDto.fromObject(objWithoutOrganizerId) + EventDtoMapper.fromObject(objWithoutOrganizerId) }).toThrow(ModelMappingError) expect(() => { - EventDto.fromObject(objWithoutStartAt) + EventDtoMapper.fromObject(objWithoutStartAt) }).toThrow(ModelMappingError) expect(() => { - EventDto.fromObject(objWithoutEndAt) + EventDtoMapper.fromObject(objWithoutEndAt) }).toThrow(ModelMappingError) expect(() => { - EventDto.fromObject(objWithoutCreatedAt) + EventDtoMapper.fromObject(objWithoutCreatedAt) }).toThrow(ModelMappingError) expect(() => { - EventDto.fromObject(objWithoutUpdatedAt) + EventDtoMapper.fromObject(objWithoutUpdatedAt) }).toThrow(ModelMappingError) expect(() => { - EventDto.fromObject(objWithoutSlug) + EventDtoMapper.fromObject(objWithoutSlug) }).toThrow(ModelMappingError) expect(() => { - EventDto.fromObject(objWithoutStatusId) + EventDtoMapper.fromObject(objWithoutStatusId) }).toThrow(ModelMappingError) expect(() => { - EventDto.fromObject(objWithoutTags) + EventDtoMapper.fromObject(objWithoutTags) }).toThrow(ModelMappingError) }) }) diff --git a/Client/reasn-client/packages/common/__tests__/models/ImageDto.test.ts b/Client/reasn-client/packages/common/__tests__/models/ImageDto.test.ts index 4888eb0b..225e8194 100644 --- a/Client/reasn-client/packages/common/__tests__/models/ImageDto.test.ts +++ b/Client/reasn-client/packages/common/__tests__/models/ImageDto.test.ts @@ -1,4 +1,4 @@ -import { ImageDto } from '@reasn/common/models/ImageDto' +import { ImageDto, ImageDtoMapper } from '@reasn/common/models/ImageDto' import ModelMappingError from '@reasn/common/errors/ModelMappingError' describe('ImageDto', () => { @@ -6,23 +6,6 @@ describe('ImageDto', () => { const objectId = 1 const objectTypeId = 1 - describe('constructor', () => { - it('should create an instance of ImageDto', () => { - let image = new ImageDto( - imageData, - objectId, - objectTypeId - ) - - expect(image).toBeInstanceOf(ImageDto) - image = image as ImageDto - - expect(image.ImageData).toBe(imageData) - expect(image.ObjectId).toBe(objectId) - expect(image.ObjectTypeId).toBe(objectTypeId) - }) - }) - describe('fromJson', () => { it('should create an instance of ImageDto from JSON string', () => { const json = `{ @@ -31,9 +14,7 @@ describe('ImageDto', () => { "ObjectTypeId": ${objectTypeId} }` - let image = ImageDto.fromJson(json) - - expect(image).toBeInstanceOf(ImageDto) + let image = ImageDtoMapper.fromJSON(json) image = image as ImageDto expect(image.ImageData).toBe(imageData) @@ -42,11 +23,7 @@ describe('ImageDto', () => { }) it('should return null if the JSON string is empty', () => { - const json = '' - - const image = ImageDto.fromJson(json) - - expect(image).toBeNull() + expect(() => ImageDtoMapper.fromJSON('')).toThrow(ModelMappingError) }) it('should throw an error when providing json without each property individually', () => { @@ -65,9 +42,9 @@ describe('ImageDto', () => { "ObjectId": ${objectId} }` - expect(() => ImageDto.fromJson(jsonWithoutImageData)).toThrow(ModelMappingError) - expect(() => ImageDto.fromJson(jsonWithoutObjectId)).toThrow(ModelMappingError) - expect(() => ImageDto.fromJson(jsonWithoutObjectTypeId)).toThrow(ModelMappingError) + expect(() => ImageDtoMapper.fromJSON(jsonWithoutImageData)).toThrow(ModelMappingError) + expect(() => ImageDtoMapper.fromJSON(jsonWithoutObjectId)).toThrow(ModelMappingError) + expect(() => ImageDtoMapper.fromJSON(jsonWithoutObjectTypeId)).toThrow(ModelMappingError) }) }) @@ -79,9 +56,7 @@ describe('ImageDto', () => { ObjectTypeId: objectTypeId } - let image = ImageDto.fromObject(object) - - expect(image).toBeInstanceOf(ImageDto) + let image = ImageDtoMapper.fromObject(object) image = image as ImageDto expect(image.ImageData).toBe(imageData) @@ -111,10 +86,10 @@ describe('ImageDto', () => { ObjectId: objectId } - expect(() => ImageDto.fromObject(object)).toThrow(ModelMappingError) - expect(() => ImageDto.fromObject(objectWithoutImageData)).toThrow(ModelMappingError) - expect(() => ImageDto.fromObject(objectWithoutObjectId)).toThrow(ModelMappingError) - expect(() => ImageDto.fromObject(objectWithoutObjectTypeId)).toThrow(ModelMappingError) + expect(() => ImageDtoMapper.fromObject(object)).toThrow(ModelMappingError) + expect(() => ImageDtoMapper.fromObject(objectWithoutImageData)).toThrow(ModelMappingError) + expect(() => ImageDtoMapper.fromObject(objectWithoutObjectId)).toThrow(ModelMappingError) + expect(() => ImageDtoMapper.fromObject(objectWithoutObjectTypeId)).toThrow(ModelMappingError) }) }) }) \ No newline at end of file diff --git a/Client/reasn-client/packages/common/__tests__/models/InterestDto.test.ts b/Client/reasn-client/packages/common/__tests__/models/InterestDto.test.ts index 642229dc..2a2a9769 100644 --- a/Client/reasn-client/packages/common/__tests__/models/InterestDto.test.ts +++ b/Client/reasn-client/packages/common/__tests__/models/InterestDto.test.ts @@ -1,20 +1,10 @@ -import { InterestDto } from '@reasn/common/models/InterestDto' +import { InterestDto, InterestDtoMapper } from '@reasn/common/models/InterestDto' import ModelMappingError from '@reasn/common/errors/ModelMappingError' describe('InterestDto', () => { const name = 'Test Interest' const level = 1 - describe('constructor', () => { - it('should create an instance of InterestDto', () => { - const interest = new InterestDto(name, level) - - expect(interest).toBeInstanceOf(InterestDto) - expect(interest.Name).toBe(name) - expect(interest.Level).toBe(level) - }) - }) - describe('fromJson', () => { it('should create an instance of InterestDto from JSON string', () => { const json = `{ @@ -22,9 +12,7 @@ describe('InterestDto', () => { "Level": ${level} }` - let interest = InterestDto.fromJson(json) - - expect(interest).toBeInstanceOf(InterestDto) + let interest = InterestDtoMapper.fromJSON(json) interest = interest as InterestDto expect(interest.Name).toBe(name) @@ -32,11 +20,7 @@ describe('InterestDto', () => { }) it('should return null if the JSON string is empty', () => { - const json = '' - - const interest = InterestDto.fromJson(json) - - expect(interest).toBeNull() + expect(() => InterestDtoMapper.fromJSON('')).toThrow(ModelMappingError) }) it('should throw an error when providing json without each property individually', () => { @@ -48,8 +32,8 @@ describe('InterestDto', () => { "Name": "${name}" }` - expect(() => InterestDto.fromJson(jsonWithoutName)).toThrow(ModelMappingError) - expect(() => InterestDto.fromJson(jsonWithoutLevel)).toThrow(ModelMappingError) + expect(() => InterestDtoMapper.fromJSON(jsonWithoutName)).toThrow(ModelMappingError) + expect(() => InterestDtoMapper.fromJSON(jsonWithoutLevel)).toThrow(ModelMappingError) }) }) @@ -60,9 +44,7 @@ describe('InterestDto', () => { Level: level } - let interest = InterestDto.fromObject(object) - - expect(interest).toBeInstanceOf(InterestDto) + let interest = InterestDtoMapper.fromObject(object) interest = interest as InterestDto expect(interest.Name).toBe(name) @@ -83,9 +65,9 @@ describe('InterestDto', () => { Name: name } - expect(() => InterestDto.fromObject(object)).toThrow(ModelMappingError) - expect(() => InterestDto.fromObject(objectWithoutName)).toThrow(ModelMappingError) - expect(() => InterestDto.fromObject(objectWithoutLevel)).toThrow(ModelMappingError) + expect(() => InterestDtoMapper.fromObject(object)).toThrow(ModelMappingError) + expect(() => InterestDtoMapper.fromObject(objectWithoutName)).toThrow(ModelMappingError) + expect(() => InterestDtoMapper.fromObject(objectWithoutLevel)).toThrow(ModelMappingError) }) }) }) \ No newline at end of file diff --git a/Client/reasn-client/packages/common/__tests__/models/ParameterDto.test.ts b/Client/reasn-client/packages/common/__tests__/models/ParameterDto.test.ts index 5c4f7561..6f4a15f6 100644 --- a/Client/reasn-client/packages/common/__tests__/models/ParameterDto.test.ts +++ b/Client/reasn-client/packages/common/__tests__/models/ParameterDto.test.ts @@ -1,20 +1,10 @@ -import { ParameterDto } from '@reasn/common/models/ParameterDto' +import { ParameterDto, ParameterDtoMapper } from '@reasn/common/models/ParameterDto' import ModelMappingError from '@reasn/common/errors/ModelMappingError' describe('ParameterDto', () => { const key = 'Test Key' const value = 'Test Value' - describe('constructor', () => { - it('should create an instance of ParameterDto', () => { - const parameter = new ParameterDto(key, value) - - expect(parameter).toBeInstanceOf(ParameterDto) - expect(parameter.Key).toBe(key) - expect(parameter.Value).toBe(value) - }) - }) - describe('fromJson', () => { it('should create an instance of ParameterDto from JSON string', () => { const json = `{ @@ -22,9 +12,7 @@ describe('ParameterDto', () => { "Value": "${value}" }` - let parameter = ParameterDto.fromJson(json) - - expect(parameter).toBeInstanceOf(ParameterDto) + let parameter = ParameterDtoMapper.fromJSON(json) parameter = parameter as ParameterDto expect(parameter.Key).toBe(key) @@ -32,11 +20,7 @@ describe('ParameterDto', () => { }) it('should return null if the JSON string is empty', () => { - const json = '' - - const parameter = ParameterDto.fromJson(json) - - expect(parameter).toBeNull() + expect(() => ParameterDtoMapper.fromJSON('')).toThrow(ModelMappingError) }) it('should throw an error when providing json without each property individually', () => { @@ -48,8 +32,8 @@ describe('ParameterDto', () => { "Key": "${key}" }` - expect(() => ParameterDto.fromJson(jsonWithoutKey)).toThrow(ModelMappingError) - expect(() => ParameterDto.fromJson(jsonWithoutValue)).toThrow(ModelMappingError) + expect(() => ParameterDtoMapper.fromJSON(jsonWithoutKey)).toThrow(ModelMappingError) + expect(() => ParameterDtoMapper.fromJSON(jsonWithoutValue)).toThrow(ModelMappingError) }) }) @@ -60,9 +44,7 @@ describe('ParameterDto', () => { Value: value } - let parameter = ParameterDto.fromObject(object) - - expect(parameter).toBeInstanceOf(ParameterDto) + let parameter = ParameterDtoMapper.fromObject(object) parameter = parameter as ParameterDto expect(parameter.Key).toBe(key) @@ -83,9 +65,9 @@ describe('ParameterDto', () => { Key: key } - expect(() => ParameterDto.fromObject(object)).toThrow(ModelMappingError) - expect(() => ParameterDto.fromObject(objectWithoutKey)).toThrow(ModelMappingError) - expect(() => ParameterDto.fromObject(objectWithoutValue)).toThrow(ModelMappingError) + expect(() => ParameterDtoMapper.fromObject(object)).toThrow(ModelMappingError) + expect(() => ParameterDtoMapper.fromObject(objectWithoutKey)).toThrow(ModelMappingError) + expect(() => ParameterDtoMapper.fromObject(objectWithoutValue)).toThrow(ModelMappingError) }) }) }) \ No newline at end of file diff --git a/Client/reasn-client/packages/common/__tests__/models/ParticipantDto.test.ts b/Client/reasn-client/packages/common/__tests__/models/ParticipantDto.test.ts index e33dba6d..1cf9eea6 100644 --- a/Client/reasn-client/packages/common/__tests__/models/ParticipantDto.test.ts +++ b/Client/reasn-client/packages/common/__tests__/models/ParticipantDto.test.ts @@ -1,22 +1,11 @@ import ModelMappingError from '@reasn/common/errors/ModelMappingError' -import { ParticipantDto } from '@reasn/common/models/ParticipantDto' +import { ParticipantDto, ParticipantDtoMapper } from '@reasn/common/models/ParticipantDto' describe('ParticipantDto', () => { const eventId = 1 const userId = 2 const statusId = 3 - describe('constructor', () => { - it('should create an instance of ParticipantDto', () => { - const participant = new ParticipantDto(eventId, userId, statusId) - - expect(participant).toBeInstanceOf(ParticipantDto) - expect(participant.EventId).toBe(eventId) - expect(participant.UserId).toBe(userId) - expect(participant.StatusId).toBe(statusId) - }) - }) - describe('fromJson', () => { it('should create an instance of ParticipantDto from JSON string', () => { const json = `{ @@ -25,9 +14,7 @@ describe('ParticipantDto', () => { "StatusId": ${statusId} }` - let participant = ParticipantDto.fromJson(json) - - expect(participant).toBeInstanceOf(ParticipantDto) + let participant = ParticipantDtoMapper.fromJSON(json) participant = participant as ParticipantDto expect(participant.EventId).toBe(eventId) @@ -36,11 +23,7 @@ describe('ParticipantDto', () => { }) it('should return null if the JSON string is empty', () => { - const json = '' - - const participant = ParticipantDto.fromJson(json) - - expect(participant).toBeNull() + expect(() => ParticipantDtoMapper.fromJSON('')).toThrow(ModelMappingError) }) it('should throw an error when providing JSON without each property individually', () => { @@ -59,9 +42,9 @@ describe('ParticipantDto', () => { "UserId": ${userId} }` - expect(() => ParticipantDto.fromJson(jsonWithoutEventId)).toThrow(ModelMappingError) - expect(() => ParticipantDto.fromJson(jsonWithoutUserId)).toThrow(ModelMappingError) - expect(() => ParticipantDto.fromJson(jsonWithoutStatusId)).toThrow(ModelMappingError) + expect(() => ParticipantDtoMapper.fromJSON(jsonWithoutEventId)).toThrow(ModelMappingError) + expect(() => ParticipantDtoMapper.fromJSON(jsonWithoutUserId)).toThrow(ModelMappingError) + expect(() => ParticipantDtoMapper.fromJSON(jsonWithoutStatusId)).toThrow(ModelMappingError) }) }) @@ -73,9 +56,7 @@ describe('ParticipantDto', () => { StatusId: statusId } - let participant = ParticipantDto.fromObject(object) - - expect(participant).toBeInstanceOf(ParticipantDto) + let participant = ParticipantDtoMapper.fromObject(object) participant = participant as ParticipantDto expect(participant.EventId).toBe(eventId) @@ -105,10 +86,10 @@ describe('ParticipantDto', () => { UserId: userId } - expect(() => ParticipantDto.fromObject(object)).toThrow(ModelMappingError) - expect(() => ParticipantDto.fromObject(objectWithoutEventId)).toThrow(ModelMappingError) - expect(() => ParticipantDto.fromObject(objectWithoutUserId)).toThrow(ModelMappingError) - expect(() => ParticipantDto.fromObject(objectWithoutStatusId)).toThrow(ModelMappingError) + expect(() => ParticipantDtoMapper.fromObject(object)).toThrow(ModelMappingError) + expect(() => ParticipantDtoMapper.fromObject(objectWithoutEventId)).toThrow(ModelMappingError) + expect(() => ParticipantDtoMapper.fromObject(objectWithoutUserId)).toThrow(ModelMappingError) + expect(() => ParticipantDtoMapper.fromObject(objectWithoutStatusId)).toThrow(ModelMappingError) }) }) }) \ No newline at end of file diff --git a/Client/reasn-client/packages/common/__tests__/models/RoleDto.test.ts b/Client/reasn-client/packages/common/__tests__/models/RoleDto.test.ts index cd038f28..b93e179f 100644 --- a/Client/reasn-client/packages/common/__tests__/models/RoleDto.test.ts +++ b/Client/reasn-client/packages/common/__tests__/models/RoleDto.test.ts @@ -1,44 +1,29 @@ import ModelMappingError from '@reasn/common/errors/ModelMappingError' -import { RoleDto } from '@reasn/common/models/RoleDto' +import { RoleDto, RoleDtoMapper } from '@reasn/common/models/RoleDto' describe('RoleDto', () => { const roleName = 'admin' - describe('constructor', () => { - it('should create an instance of RoleDto', () => { - const role = new RoleDto(roleName) - - expect(role).toBeInstanceOf(RoleDto) - expect(role.Name).toBe(roleName) - }) - }) - describe('fromJson', () => { it('should create an instance of RoleDto from JSON string', () => { const json = `{ "Name": "${roleName}" }` - let role = RoleDto.fromJson(json) - - expect(role).toBeInstanceOf(RoleDto) + let role = RoleDtoMapper.fromJSON(json) role = role as RoleDto expect(role.Name).toBe(roleName) }) it('should return null if the JSON string is empty', () => { - const json = '' - - const role = RoleDto.fromJson(json) - - expect(role).toBeNull() + expect(() => RoleDtoMapper.fromJSON('')).toThrow(ModelMappingError) }) it('should throw an error when providing JSON without each property individually', () => { const jsonWithoutName = `{}` - expect(() => RoleDto.fromJson(jsonWithoutName)).toThrow(ModelMappingError) + expect(() => RoleDtoMapper.fromJSON(jsonWithoutName)).toThrow(ModelMappingError) }) }) @@ -48,9 +33,7 @@ describe('RoleDto', () => { Name: roleName } - let role = RoleDto.fromObject(object) - - expect(role).toBeInstanceOf(RoleDto) + let role = RoleDtoMapper.fromObject(object) role = role as RoleDto expect(role.Name).toBe(roleName) @@ -63,8 +46,8 @@ describe('RoleDto', () => { const objectWithoutName = {} - expect(() => RoleDto.fromObject(object)).toThrow(ModelMappingError) - expect(() => RoleDto.fromObject(objectWithoutName)).toThrow(ModelMappingError) + expect(() => RoleDtoMapper.fromObject(object)).toThrow(ModelMappingError) + expect(() => RoleDtoMapper.fromObject(objectWithoutName)).toThrow(ModelMappingError) }) }) }) \ No newline at end of file diff --git a/Client/reasn-client/packages/common/__tests__/models/StatusDto.test.ts b/Client/reasn-client/packages/common/__tests__/models/StatusDto.test.ts index 8462a517..88ad44c5 100644 --- a/Client/reasn-client/packages/common/__tests__/models/StatusDto.test.ts +++ b/Client/reasn-client/packages/common/__tests__/models/StatusDto.test.ts @@ -1,20 +1,10 @@ import ModelMappingError from '@reasn/common/errors/ModelMappingError' -import { StatusDto } from '@reasn/common/models/StatusDto' +import { StatusDto, StatusDtoMapper } from '@reasn/common/models/StatusDto' describe('StatusDto', () => { const statusName = 'Active' const objectTypeId = 1 - describe('constructor', () => { - it('should create an instance of StatusDto', () => { - const status = new StatusDto(statusName, objectTypeId) - - expect(status).toBeInstanceOf(StatusDto) - expect(status.Name).toBe(statusName) - expect(status.ObjectTypeId).toBe(objectTypeId) - }) - }) - describe('fromJson', () => { it('should create an instance of StatusDto from JSON string', () => { const json = `{ @@ -22,9 +12,7 @@ describe('StatusDto', () => { "ObjectTypeId": ${objectTypeId} }` - let status = StatusDto.fromJson(json) - - expect(status).toBeInstanceOf(StatusDto) + let status = StatusDtoMapper.fromJSON(json) status = status as StatusDto expect(status.Name).toBe(statusName) @@ -32,11 +20,7 @@ describe('StatusDto', () => { }) it('should return null if the JSON string is empty', () => { - const json = '' - - const status = StatusDto.fromJson(json) - - expect(status).toBeNull() + expect(() => StatusDtoMapper.fromJSON('')).toThrow(ModelMappingError) }) it('should throw an error when providing JSON without each property individually', () => { @@ -48,8 +32,8 @@ describe('StatusDto', () => { "ObjectTypeId": ${objectTypeId} }` - expect(() => StatusDto.fromJson(jsonWithoutName)).toThrow(ModelMappingError) - expect(() => StatusDto.fromJson(jsonWithoutObjectTypeId)).toThrow(ModelMappingError) + expect(() => StatusDtoMapper.fromJSON(jsonWithoutName)).toThrow(ModelMappingError) + expect(() => StatusDtoMapper.fromJSON(jsonWithoutObjectTypeId)).toThrow(ModelMappingError) }) }) @@ -60,9 +44,7 @@ describe('StatusDto', () => { ObjectTypeId: objectTypeId } - let status = StatusDto.fromObject(object) - - expect(status).toBeInstanceOf(StatusDto) + let status = StatusDtoMapper.fromObject(object) status = status as StatusDto expect(status.Name).toBe(statusName) @@ -83,9 +65,9 @@ describe('StatusDto', () => { Name: statusName } - expect(() => StatusDto.fromObject(object)).toThrow(ModelMappingError) - expect(() => StatusDto.fromObject(objectWithoutName)).toThrow(ModelMappingError) - expect(() => StatusDto.fromObject(objectWithoutObjectTypeId)).toThrow(ModelMappingError) + expect(() => StatusDtoMapper.fromObject(object)).toThrow(ModelMappingError) + expect(() => StatusDtoMapper.fromObject(objectWithoutName)).toThrow(ModelMappingError) + expect(() => StatusDtoMapper.fromObject(objectWithoutObjectTypeId)).toThrow(ModelMappingError) }) }) }) \ No newline at end of file diff --git a/Client/reasn-client/packages/common/__tests__/models/TagDto.test.ts b/Client/reasn-client/packages/common/__tests__/models/TagDto.test.ts index 33819cf1..44f762e7 100644 --- a/Client/reasn-client/packages/common/__tests__/models/TagDto.test.ts +++ b/Client/reasn-client/packages/common/__tests__/models/TagDto.test.ts @@ -1,44 +1,29 @@ import ModelMappingError from '@reasn/common/errors/ModelMappingError' -import { TagDto } from '@reasn/common/models/TagDto' +import { TagDto, TagDtoMapper } from '@reasn/common/models/TagDto' describe('TagDto', () => { const name = 'tag name' - describe('constructor', () => { - it('should create an instance of TagDto', () => { - const tag = new TagDto(name) - - expect(tag).toBeInstanceOf(TagDto) - expect(tag.Name).toBe(name) - }) - }) - describe('fromJson', () => { it('should create an instance of TagDto from JSON string', () => { const json = `{ "Name": "${name}" }` - let tag = TagDto.fromJson(json) - - expect(tag).toBeInstanceOf(TagDto) + let tag = TagDtoMapper.fromJSON(json) tag = tag as TagDto expect(tag.Name).toBe(name) }) it('should return null if the JSON string is empty', () => { - const json = '' - - const tag = TagDto.fromJson(json) - - expect(tag).toBeNull() + expect(() => TagDtoMapper.fromJSON('')).toThrow(ModelMappingError) }) it('should throw an error when providing JSON without the Name property', () => { const jsonWithoutName = `{}` - expect(() => TagDto.fromJson(jsonWithoutName)).toThrow(ModelMappingError) + expect(() => TagDtoMapper.fromJSON(jsonWithoutName)).toThrow(ModelMappingError) }) }) @@ -48,9 +33,7 @@ describe('TagDto', () => { Name: name } - let tag = TagDto.fromObject(object) - - expect(tag).toBeInstanceOf(TagDto) + let tag = TagDtoMapper.fromObject(object) tag = tag as TagDto expect(tag.Name).toBe(name) @@ -63,8 +46,8 @@ describe('TagDto', () => { const objectWithoutName = {} - expect(() => TagDto.fromObject(object)).toThrow(ModelMappingError) - expect(() => TagDto.fromObject(objectWithoutName)).toThrow(ModelMappingError) + expect(() => TagDtoMapper.fromObject(object)).toThrow(ModelMappingError) + expect(() => TagDtoMapper.fromObject(objectWithoutName)).toThrow(ModelMappingError) }) }) }) \ No newline at end of file diff --git a/Client/reasn-client/packages/common/__tests__/models/UserDto.test.ts b/Client/reasn-client/packages/common/__tests__/models/UserDto.test.ts index 63ad758e..7121fbb8 100644 --- a/Client/reasn-client/packages/common/__tests__/models/UserDto.test.ts +++ b/Client/reasn-client/packages/common/__tests__/models/UserDto.test.ts @@ -1,5 +1,5 @@ import ModelMappingError from '@reasn/common/errors/ModelMappingError' -import { UserDto } from '@reasn/common/models/UserDto' +import { UserDto, UserDtoMapper } from '@reasn/common/models/UserDto' import { InterestDto } from '@reasn/common/models/InterestDto' describe('UserDto', () => { @@ -15,22 +15,6 @@ describe('UserDto', () => { { Name: 'Music', Level: 3 } ] - describe('constructor', () => { - it('should create an instance of UserDto', () => { - const user = new UserDto(username, name, surname, email, phone, roleId, addressId, interests) - - expect(user).toBeInstanceOf(UserDto) - expect(user.Username).toBe(username) - expect(user.Name).toBe(name) - expect(user.Surname).toBe(surname) - expect(user.Email).toBe(email) - expect(user.Phone).toBe(phone) - expect(user.RoleId).toBe(roleId) - expect(user.AddressId).toBe(addressId) - expect(user.Intrests).toBe(interests) - }) - }) - describe('fromJson', () => { it('should create an instance of UserDto from JSON string', () => { const json = `{ @@ -44,9 +28,7 @@ describe('UserDto', () => { "Intrests": ${JSON.stringify(interests)} }` - let user = UserDto.fromJson(json) - - expect(user).toBeInstanceOf(UserDto) + let user = UserDtoMapper.fromJSON(json) user = user as UserDto expect(user.Username).toBe(username) @@ -60,11 +42,7 @@ describe('UserDto', () => { }) it('should return null if the JSON string is empty', () => { - const json = '' - - const user = UserDto.fromJson(json) - - expect(user).toBeNull() + expect(() => UserDtoMapper.fromJSON('')).toThrow(ModelMappingError) }) it('should throw an error when providing JSON without each property individually', () => { @@ -148,14 +126,14 @@ describe('UserDto', () => { "AddressId": ${addressId} }` - expect(() => UserDto.fromJson(jsonWithoutUsername)).toThrow(ModelMappingError) - expect(() => UserDto.fromJson(jsonWithoutName)).toThrow(ModelMappingError) - expect(() => UserDto.fromJson(jsonWithoutSurname)).toThrow(ModelMappingError) - expect(() => UserDto.fromJson(jsonWithoutEmail)).toThrow(ModelMappingError) - expect(() => UserDto.fromJson(jsonWithoutPhone)).toThrow(ModelMappingError) - expect(() => UserDto.fromJson(jsonWithoutRoleId)).toThrow(ModelMappingError) - expect(() => UserDto.fromJson(jsonWithoutAddressId)).toThrow(ModelMappingError) - expect(() => UserDto.fromJson(jsonWithoutInterests)).toThrow(ModelMappingError) + expect(() => UserDtoMapper.fromJSON(jsonWithoutUsername)).toThrow(ModelMappingError) + expect(() => UserDtoMapper.fromJSON(jsonWithoutName)).toThrow(ModelMappingError) + expect(() => UserDtoMapper.fromJSON(jsonWithoutSurname)).toThrow(ModelMappingError) + expect(() => UserDtoMapper.fromJSON(jsonWithoutEmail)).toThrow(ModelMappingError) + expect(() => UserDtoMapper.fromJSON(jsonWithoutPhone)).toThrow(ModelMappingError) + expect(() => UserDtoMapper.fromJSON(jsonWithoutRoleId)).toThrow(ModelMappingError) + expect(() => UserDtoMapper.fromJSON(jsonWithoutAddressId)).toThrow(ModelMappingError) + expect(() => UserDtoMapper.fromJSON(jsonWithoutInterests)).toThrow(ModelMappingError) }) }) @@ -172,9 +150,7 @@ describe('UserDto', () => { Intrests: interests } - let user = UserDto.fromObject(object) - - expect(user).toBeInstanceOf(UserDto) + let user = UserDtoMapper.fromObject(object) user = user as UserDto expect(user.Username).toBe(username) @@ -279,15 +255,15 @@ describe('UserDto', () => { AddressId: addressId, } - expect(() => UserDto.fromObject(object)).toThrow(ModelMappingError) - expect(() => UserDto.fromObject(objectWithoutUsername)).toThrow(ModelMappingError) - expect(() => UserDto.fromObject(objectWithoutName)).toThrow(ModelMappingError) - expect(() => UserDto.fromObject(objectWithoutSurname)).toThrow(ModelMappingError) - expect(() => UserDto.fromObject(objectWithoutEmail)).toThrow(ModelMappingError) - expect(() => UserDto.fromObject(objectWithoutPhone)).toThrow(ModelMappingError) - expect(() => UserDto.fromObject(objectWithoutRoleId)).toThrow(ModelMappingError) - expect(() => UserDto.fromObject(objectWithoutAddressId)).toThrow(ModelMappingError) - expect(() => UserDto.fromObject(objectWithoutInterests)).toThrow(ModelMappingError) + expect(() => UserDtoMapper.fromObject(object)).toThrow(ModelMappingError) + expect(() => UserDtoMapper.fromObject(objectWithoutUsername)).toThrow(ModelMappingError) + expect(() => UserDtoMapper.fromObject(objectWithoutName)).toThrow(ModelMappingError) + expect(() => UserDtoMapper.fromObject(objectWithoutSurname)).toThrow(ModelMappingError) + expect(() => UserDtoMapper.fromObject(objectWithoutEmail)).toThrow(ModelMappingError) + expect(() => UserDtoMapper.fromObject(objectWithoutPhone)).toThrow(ModelMappingError) + expect(() => UserDtoMapper.fromObject(objectWithoutRoleId)).toThrow(ModelMappingError) + expect(() => UserDtoMapper.fromObject(objectWithoutAddressId)).toThrow(ModelMappingError) + expect(() => UserDtoMapper.fromObject(objectWithoutInterests)).toThrow(ModelMappingError) }) }) }) \ No newline at end of file