Skip to content
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

[2.x] Change current team of user when creating a new additional team #618

Merged
merged 8 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion stubs/app/Actions/Jetstream/CreateTeam.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ public function create($user, array $input)

AddingTeam::dispatch($user);

return $user->ownedTeams()->create([
$team = $user->ownedTeams()->create([
'name' => $input['name'],
'personal_team' => false,
]);

$user->forceFill([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rethinking this for the failed tests:

Suggested change
$user->forceFill([
$user->switchTeam($team);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying now!

Copy link
Contributor Author

@OscarKolsrud OscarKolsrud Jan 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joelbutcher That seems to solve the failing tests! But lastly i cant wrap my head around why StyleCI is bugging us. That file looks perfectly fine to me. Do you see any thing? EDIT: Solved it!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OscarKolsrud it's the white space after

         $personalTeam->forceFill(['personal_team' => true])->save();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed! All tests passing! I think this is now ready to merge :)

'current_team_id' => $team->id,
])->save();

return $team;
}
}
6 changes: 2 additions & 4 deletions tests/TeamBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,10 @@ public function test_user_does_not_need_to_refresh_after_switching_teams()
$personalTeam = $action->create($user, ['name' => 'Personal Team']);

$personalTeam->forceFill(['personal_team' => true])->save();

$anotherTeam = $action->create($user, ['name' => 'Test Team']);


$this->assertTrue($user->isCurrentTeam($personalTeam));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just move this line to before the previous line is executed?


$user->switchTeam($anotherTeam);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can be removed now.

Suggested change
$user->switchTeam($anotherTeam);

$anotherTeam = $action->create($user, ['name' => 'Test Team']);

$this->assertTrue($user->isCurrentTeam($anotherTeam));
}
Expand Down