|
9 | 9 | } from 'src/otomi-models' |
10 | 10 | import OtomiStack from 'src/otomi-stack' |
11 | 11 | import { loadSpec } from './app' |
12 | | -import { ValidationError } from './error' |
| 12 | +import { NotExistError, ValidationError } from './error' |
13 | 13 | import { Git } from './git' |
14 | 14 |
|
15 | 15 | jest.mock('./tty', () => ({ |
@@ -621,6 +621,60 @@ describe('Users tests', () => { |
621 | 621 | }) |
622 | 622 | }) |
623 | 623 |
|
| 624 | + it('should not allow editing a user into a team that does not exist', async () => { |
| 625 | + createTestTeam(otomiStack, 'team1') |
| 626 | + |
| 627 | + const user = { |
| 628 | + ...teamMember1, |
| 629 | + id: 'missing-team-user', |
| 630 | + email: 'missing-team-user@dev.linode-apl.net', |
| 631 | + teams: ['team1'], |
| 632 | + } |
| 633 | + |
| 634 | + createTestUser(otomiStack, user) |
| 635 | + |
| 636 | + await expect( |
| 637 | + otomiStack.editUser( |
| 638 | + user.id!, |
| 639 | + { |
| 640 | + ...user, |
| 641 | + teams: ['team1', 'team-does-not-exist'], |
| 642 | + }, |
| 643 | + platformAdminSession, |
| 644 | + ), |
| 645 | + ).rejects.toThrow(new NotExistError('Team(s) not found: team-does-not-exist')) |
| 646 | + |
| 647 | + expect(mockGit.writeTextFile).not.toHaveBeenCalled() |
| 648 | + expect(otomiStack.doDeployment).not.toHaveBeenCalled() |
| 649 | + }) |
| 650 | + |
| 651 | + it('should allow editing a user into existing teams', async () => { |
| 652 | + createTestTeam(otomiStack, 'team1') |
| 653 | + createTestTeam(otomiStack, 'team2') |
| 654 | + |
| 655 | + const user = { |
| 656 | + ...teamMember1, |
| 657 | + id: 'existing-team-user', |
| 658 | + email: 'existing-team-user@dev.linode-apl.net', |
| 659 | + teams: ['team1'], |
| 660 | + } |
| 661 | + |
| 662 | + createTestUser(otomiStack, user) |
| 663 | + |
| 664 | + const result = await otomiStack.editUser( |
| 665 | + user.id!, |
| 666 | + { |
| 667 | + ...user, |
| 668 | + teams: ['team1', 'team2'], |
| 669 | + }, |
| 670 | + platformAdminSession, |
| 671 | + ) |
| 672 | + |
| 673 | + expect(result.teams).toEqual(['team1', 'team2']) |
| 674 | + expect(mockGit.writeTextFile).toHaveBeenCalled() |
| 675 | + expect(otomiStack.doDeployment).toHaveBeenCalled() |
| 676 | + }) |
| 677 | + |
624 | 678 | describe('canTeamAdminUpdateUserTeams', () => { |
625 | 679 | // set session user as team admin |
626 | 680 | sessionUser.isPlatformAdmin = false |
|
0 commit comments