-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin' into BC-5522-impl-of-deletion-api
- Loading branch information
Showing
24 changed files
with
716 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './rocket-chat-user.do'; |
67 changes: 67 additions & 0 deletions
67
apps/server/src/modules/rocketchat-user/domain/rocket-chat-user.do.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { ObjectId } from '@mikro-orm/mongodb'; | ||
import { RocketChatUser } from './rocket-chat-user.do'; | ||
import { rocketChatUserFactory } from './testing/rocket-chat-user.factory'; | ||
|
||
describe(RocketChatUser.name, () => { | ||
describe('constructor', () => { | ||
describe('When constructor is called', () => { | ||
it('should create a rocketChatUser by passing required properties', () => { | ||
const domainObject: RocketChatUser = rocketChatUserFactory.build(); | ||
|
||
expect(domainObject instanceof RocketChatUser).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe('when passed a valid id', () => { | ||
const setup = () => { | ||
const domainObject: RocketChatUser = rocketChatUserFactory.build(); | ||
|
||
return { domainObject }; | ||
}; | ||
|
||
it('should set the id', () => { | ||
const { domainObject } = setup(); | ||
|
||
const rocketChatUserObject: RocketChatUser = new RocketChatUser(domainObject); | ||
|
||
expect(rocketChatUserObject.id).toEqual(domainObject.id); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('getters', () => { | ||
describe('When getters are used', () => { | ||
const setup = () => { | ||
const props = { | ||
id: new ObjectId().toHexString(), | ||
userId: new ObjectId().toHexString(), | ||
username: 'Test.User.shls', | ||
rcId: 'JfMJXua6t29KYXdDc', | ||
authToken: 'OL8e5YCZHy3agGnLS-gHAx1wU4ZCG8-DXU_WZnUxUu6', | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
}; | ||
|
||
const rocketChatUserDo = new RocketChatUser(props); | ||
|
||
return { props, rocketChatUserDo }; | ||
}; | ||
|
||
it('getters should return proper values', () => { | ||
const { props, rocketChatUserDo } = setup(); | ||
|
||
const gettersValues = { | ||
id: rocketChatUserDo.id, | ||
userId: rocketChatUserDo.userId, | ||
username: rocketChatUserDo.username, | ||
rcId: rocketChatUserDo.rcId, | ||
authToken: rocketChatUserDo.authToken, | ||
createdAt: rocketChatUserDo.createdAt, | ||
updatedAt: rocketChatUserDo.updatedAt, | ||
}; | ||
|
||
expect(gettersValues).toEqual(props); | ||
}); | ||
}); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
apps/server/src/modules/rocketchat-user/domain/rocket-chat-user.do.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { EntityId } from '@shared/domain/types'; | ||
import { AuthorizableObject, DomainObject } from '@shared/domain/domain-object'; | ||
|
||
export interface RocketChatUserProps extends AuthorizableObject { | ||
userId: EntityId; | ||
username: string; | ||
rcId: string; | ||
authToken?: string; | ||
createdAt?: Date; | ||
updatedAt?: Date; | ||
} | ||
|
||
export class RocketChatUser extends DomainObject<RocketChatUserProps> { | ||
get userId(): EntityId { | ||
return this.props.userId; | ||
} | ||
|
||
get username(): string { | ||
return this.props.username; | ||
} | ||
|
||
get rcId(): string { | ||
return this.props.rcId; | ||
} | ||
|
||
get authToken(): string | undefined { | ||
return this.props.authToken; | ||
} | ||
|
||
get createdAt(): Date | undefined { | ||
return this.props.createdAt; | ||
} | ||
|
||
get updatedAt(): Date | undefined { | ||
return this.props.updatedAt; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
apps/server/src/modules/rocketchat-user/domain/testing/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './rocket-chat-user.factory'; |
18 changes: 18 additions & 0 deletions
18
apps/server/src/modules/rocketchat-user/domain/testing/rocket-chat-user.factory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { ObjectId } from '@mikro-orm/mongodb'; | ||
import { BaseFactory } from '@shared/testing'; | ||
import { RocketChatUser, RocketChatUserProps } from '../rocket-chat-user.do'; | ||
|
||
export const rocketChatUserFactory = BaseFactory.define<RocketChatUser, RocketChatUserProps>( | ||
RocketChatUser, | ||
({ sequence }) => { | ||
return { | ||
id: new ObjectId().toHexString(), | ||
userId: new ObjectId().toHexString(), | ||
username: `username-${sequence}`, | ||
rcId: `rcId-${sequence}`, | ||
authToken: `aythToken-${sequence}`, | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
}; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './rocket-chat-user.entity'; |
61 changes: 61 additions & 0 deletions
61
apps/server/src/modules/rocketchat-user/entity/rocket-chat-user.entity.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { setupEntities } from '@shared/testing'; | ||
import { ObjectId } from '@mikro-orm/mongodb'; | ||
import { RocketChatUserEntity } from '@src/modules/rocketchat-user/entity'; | ||
|
||
describe(RocketChatUserEntity.name, () => { | ||
beforeAll(async () => { | ||
await setupEntities(); | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const setup = () => { | ||
const props = { | ||
id: new ObjectId().toHexString(), | ||
userId: new ObjectId(), | ||
username: 'Test.User.shls', | ||
rcId: 'JfMJXua6t29KYXdDc', | ||
authToken: 'OL8e5YCZHy3agGnLS-gHAx1wU4ZCG8-DXU_WZnUxUu6', | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
}; | ||
|
||
return { props }; | ||
}; | ||
|
||
describe('constructor', () => { | ||
describe('When constructor is called', () => { | ||
it('should throw an error by empty constructor', () => { | ||
// @ts-expect-error: Test case | ||
const test = () => new RocketChatUserEntity(); | ||
expect(test).toThrow(); | ||
}); | ||
|
||
it('should create a rocketChatUser by passing required properties', () => { | ||
const { props } = setup(); | ||
const entity: RocketChatUserEntity = new RocketChatUserEntity(props); | ||
|
||
expect(entity instanceof RocketChatUserEntity).toEqual(true); | ||
}); | ||
|
||
it(`should return a valid object with fields values set from the provided complete props object`, () => { | ||
const { props } = setup(); | ||
const entity: RocketChatUserEntity = new RocketChatUserEntity(props); | ||
|
||
const entityProps = { | ||
id: entity.id, | ||
userId: entity.userId, | ||
username: entity.username, | ||
rcId: entity.rcId, | ||
authToken: entity.authToken, | ||
createdAt: entity.createdAt, | ||
updatedAt: entity.updatedAt, | ||
}; | ||
|
||
expect(entityProps).toEqual(props); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.