| 660 | } |
| 661 | |
| 662 | func TestSearchUsers(t *testing.T) { |
| 663 | t.Parallel() |
| 664 | testCases := []struct { |
| 665 | Name string |
| 666 | Query string |
| 667 | Expected database.GetUsersParams |
| 668 | ExpectedErrorContains string |
| 669 | }{ |
| 670 | { |
| 671 | Name: "Empty", |
| 672 | Query: "", |
| 673 | Expected: database.GetUsersParams{ |
| 674 | Status: []database.UserStatus{}, |
| 675 | RbacRole: []string{}, |
| 676 | LoginType: []database.LoginType{}, |
| 677 | }, |
| 678 | }, |
| 679 | { |
| 680 | Name: "Username", |
| 681 | Query: "user-name", |
| 682 | Expected: database.GetUsersParams{ |
| 683 | Search: "user-name", |
| 684 | Status: []database.UserStatus{}, |
| 685 | RbacRole: []string{}, |
| 686 | LoginType: []database.LoginType{}, |
| 687 | }, |
| 688 | }, |
| 689 | { |
| 690 | Name: "UsernameWithSpaces", |
| 691 | Query: " user-name ", |
| 692 | Expected: database.GetUsersParams{ |
| 693 | Search: "user-name", |
| 694 | Status: []database.UserStatus{}, |
| 695 | RbacRole: []string{}, |
| 696 | LoginType: []database.LoginType{}, |
| 697 | }, |
| 698 | }, |
| 699 | { |
| 700 | Name: "Username+Param", |
| 701 | Query: "usEr-name stAtus:actiVe", |
| 702 | Expected: database.GetUsersParams{ |
| 703 | Search: "user-name", |
| 704 | Status: []database.UserStatus{database.UserStatusActive}, |
| 705 | RbacRole: []string{}, |
| 706 | LoginType: []database.LoginType{}, |
| 707 | }, |
| 708 | }, |
| 709 | { |
| 710 | Name: "OnlyParams", |
| 711 | Query: "status:acTIve sEArch:User-Name role:Owner", |
| 712 | Expected: database.GetUsersParams{ |
| 713 | Search: "user-name", |
| 714 | Status: []database.UserStatus{database.UserStatusActive}, |
| 715 | RbacRole: []string{codersdk.RoleOwner}, |
| 716 | LoginType: []database.LoginType{}, |
| 717 | }, |
| 718 | }, |
| 719 | { |