-
Notifications
You must be signed in to change notification settings - Fork 212
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
[CIS-259] Implement teams #905
Conversation
Codecov Report
@@ Coverage Diff @@
## main #905 +/- ##
==========================================
+ Coverage 87.11% 89.01% +1.90%
==========================================
Files 238 200 -38
Lines 9147 8130 -1017
==========================================
- Hits 7968 7237 -731
+ Misses 1179 893 -286
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
926ff5c
to
9c8030d
Compare
9c8030d
to
a420ccc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, the tests should be in the same commit as the implementation, so it's easy to verify what's happening there.
It seems there are no tests for DTOs, correct? I see only tests for the payload serialization.
Sources/StreamChat/APIClient/Endpoints/Payloads/ChannelListPayload.swift
Show resolved
Hide resolved
a420ccc
to
53b6893
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great Job 💪 Just added some questions 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there... just some nits
|
||
let teamsArray: [TeamDTO] = try payload.teams.map { | ||
let team = try saveTeam(teamId: $0) | ||
team.users.insert(dto) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is IMO not needed. The relationship is already set on L120
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay this is probably my gap in CoreData knowledge... But now I see you are right. It handles automatically... Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So will you remove it then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
14272dc
to
605a588
Compare
func test_teamsForUser_areStoredAndLoadedFromDB() { | ||
let teamIds: [TeamId] = [.unique, .unique, .unique] | ||
let userId: UserId = .unique | ||
|
||
let payload: UserPayload<NoExtraData> = .dummy(userId: userId, teams: teamIds) | ||
|
||
// Asynchronously save the user payload to the db, which should save teams for user as well. | ||
try! database.writeSynchronously { session in | ||
try! session.saveUser(payload: payload) | ||
} | ||
|
||
// Load the user from the db and check the fields are correct | ||
var loadedUserDTO: UserDTO? { | ||
database.viewContext.user(id: userId) | ||
} | ||
|
||
XCTAssertEqual(payload.teams.count, loadedUserDTO?.teams?.count) | ||
XCTAssertEqual(loadedUserDTO?.teams?.first?.users.first, loadedUserDTO) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be among UserDTO
tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved.
func test_teamForChannel_isStoredAndLoadedFromDB() { | ||
let teamId: TeamId = .unique | ||
let channelId: ChannelId = .unique | ||
|
||
let channelDetailPayload: ChannelDetailPayload<NoExtraData> = .dummy(cid: channelId, teamId: teamId) | ||
|
||
// Asynchronously save the channel payload to the db, which should save the team for the channel as well. | ||
try! database.writeSynchronously { session in | ||
try! session.saveChannel(payload: channelDetailPayload, query: nil) | ||
} | ||
|
||
// Load the channel from the db and check the team is correct | ||
var loadedChannelDTO: ChannelDTO? { | ||
database.viewContext.channel(cid: channelId) | ||
} | ||
|
||
XCTAssertEqual(channelDetailPayload.team, loadedChannelDTO?.team?.id) | ||
XCTAssertEqual(loadedChannelDTO?.team?.channels.first, loadedChannelDTO) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be among ChannelDTO
tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved... and deleted file 🧙🏻♂️
try! database.writeSynchronously { session in | ||
try! session.saveUser(payload: payload) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you mark the test throws
you can change try!
to try
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
var loadedUserDTO: UserDTO? { | ||
database.viewContext.user(id: userId) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let loadedUser = try XCTUnwrap(database.viewContext.user(id: userId))
would work better here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn that copypasting... Changed.
|
||
let teamsArray: [TeamDTO] = try payload.teams.map { | ||
let team = try saveTeam(teamId: $0) | ||
team.users.insert(dto) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So will you remove it then?
static func dummy(cid: ChannelId) -> ChannelDetailPayload { | ||
static func dummy(cid: ChannelId, teamId: TeamId? = nil) -> ChannelDetailPayload { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is needed tbh :) Why no just assign .unique
to the team
variable like we do it with other things?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I guess you are right, I wanted to have control over with which teams I creat and assign to dummy, but I guess it needs to be known only for cid
. Thanks fixed.
@@ -43,6 +44,8 @@ class UserDTO_Tests: XCTestCase { | |||
Assert.willBeEqual(payload.createdAt, loadedUserDTO?.userCreatedAt) | |||
Assert.willBeEqual(payload.updatedAt, loadedUserDTO?.userUpdatedAt) | |||
Assert.willBeEqual(payload.lastActiveAt, loadedUserDTO?.lastActivityAt) | |||
Assert.willBeEqual(payload.teams.first, loadedUserDTO?.teams?.first?.id) | |||
Assert.willBeEqual(loadedUserDTO?.teams?.first?.users.first, loadedUserDTO) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What exactly are you testing here? 🤯 This is already taken care of by CoreData, we don't need to test it explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started to panic when I figured out there are relationships to the TeamDTO
, so I started to manually assign the relationships and test it... Only to figure out I don't need to :D
@@ -43,6 +44,8 @@ class UserDTO_Tests: XCTestCase { | |||
Assert.willBeEqual(payload.createdAt, loadedUserDTO?.userCreatedAt) | |||
Assert.willBeEqual(payload.updatedAt, loadedUserDTO?.userUpdatedAt) | |||
Assert.willBeEqual(payload.lastActiveAt, loadedUserDTO?.lastActivityAt) | |||
Assert.willBeEqual(payload.teams.first, loadedUserDTO?.teams?.first?.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can be more specific here a do something like:
Assert.willBeEqual(payload.teams.sorted(), loadedUserDTO?.teams?.map { $0.id }.sorted())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, much better..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool 🎉 There's are still some strange things happening in tests. Please fix and it's good to 🚢
CHANGELOG.md
Outdated
@@ -20,6 +20,7 @@ _March 12, 2021_ | |||
- Expose `membership` value on `ChatChannel` which contains information about the current user membership [#885](https://github.com/GetStream/stream-chat-swift/issues/885) | |||
- `ChatChannelMember` now contains channel-specific ban information: `isBannedFromChannel` and `banExpiresAt` [#885](https://github.com/GetStream/stream-chat-swift/issues/885) | |||
- Channel-specific ban events are handled and the models are properly updated [#885](https://github.com/GetStream/stream-chat-swift/pull/885) | |||
- Introduce support for [multitenancy](https://getstream.io/chat/docs/react/multi_tenant_chat/?language=swift) - `teams` for `User` and `team` for `Channel` are now exposed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The link to the PR is missing (see other CHANGELOG items please)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed❗️
605a588
to
2e30974
Compare
Co-authored-by: Dominik Bucher <d.bucher@centrum.cz>
2e30974
to
b7ab3f3
Compare
Co-authored-by: Dominik Bucher <d.bucher@centrum.cz>
Co-authored-by: Dominik Bucher <d.bucher@centrum.cz>
Co-authored-by: Dominik Bucher <d.bucher@centrum.cz>
Co-authored-by: Dominik Bucher <d.bucher@centrum.cz>
b7ab3f3
to
966312c
Compare
What this PR do:
How to test it
teams
property is parsed from payload.Where you can start
UserPayload
andChannelListPayload
, check if there is correct relationship between objects.