Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: clean up supplier login implementation
Signed-off-by: Otieno Calvine <nyarangaotieno@gmail.com>
- Loading branch information
Showing
8 changed files
with
1,698 additions
and
3,508 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,218 +1 @@ | ||
package dto | ||
|
||
import ( | ||
"net/url" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/savannahghi/enumutils" | ||
) | ||
|
||
func TestBusinessPartnerFilterInput_ToURLValues(t *testing.T) { | ||
var ( | ||
search = "data" | ||
name = "somename" | ||
sladeCode = "slasde" | ||
) | ||
|
||
correctFilters := BusinessPartnerFilterInput{ | ||
Search: &search, | ||
Name: &name, | ||
SladeCode: &sladeCode, | ||
} | ||
|
||
failingFilters := BusinessPartnerFilterInput{ | ||
Search: &search, | ||
} | ||
|
||
expectedFilter := url.Values{ | ||
"search": []string{search}, | ||
"name": []string{name}, | ||
"slade_code": []string{sladeCode}, | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
filter BusinessPartnerFilterInput | ||
wantValues url.Values | ||
wantError bool | ||
}{ | ||
{ | ||
name: "success url values transformation", | ||
filter: correctFilters, | ||
wantValues: expectedFilter, | ||
wantError: false, | ||
}, | ||
{ | ||
name: "bad filter data", | ||
filter: failingFilters, | ||
wantValues: expectedFilter, | ||
wantError: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if !reflect.DeepEqual(tt.wantValues, tt.filter.ToURLValues()) && !tt.wantError { | ||
t.Errorf("BusinessPartnerFilterInput.ToURLValues() = %v, want %v", tt.filter.ToURLValues(), tt.wantValues) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestBusinessPartnerSortInput_ToURLValues(t *testing.T) { | ||
|
||
var name enumutils.SortOrder = enumutils.SortOrderAsc | ||
var sladeCode enumutils.SortOrder = enumutils.SortOrderAsc | ||
var sladeCode2 enumutils.SortOrder = enumutils.SortOrderDesc | ||
|
||
correctFilters := BusinessPartnerSortInput{ | ||
Name: &name, | ||
SladeCode: &sladeCode, | ||
} | ||
|
||
failingFilters := BusinessPartnerSortInput{ | ||
Name: &name, | ||
SladeCode: &sladeCode2, | ||
} | ||
|
||
expectedSortValue := url.Values{ | ||
"order_by": []string{"name"}, | ||
"slade_code": []string{"number"}, | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
filter BusinessPartnerSortInput | ||
wantValues url.Values | ||
wantError bool | ||
}{ | ||
{ | ||
name: "success passing sort filter", | ||
filter: correctFilters, | ||
wantValues: expectedSortValue, | ||
wantError: false, | ||
}, | ||
{ | ||
name: "bad filters", | ||
filter: failingFilters, | ||
wantValues: expectedSortValue, | ||
wantError: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if !reflect.DeepEqual(tt.wantValues, tt.filter.ToURLValues()) && !tt.wantError { | ||
t.Errorf("BusinessPartnerSortInput.ToURLValues() = %v, want %v", tt.filter.ToURLValues(), tt.wantValues) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestBranchSortInput_ToURLValues(t *testing.T) { | ||
var name enumutils.SortOrder = enumutils.SortOrderAsc | ||
var sladeCode enumutils.SortOrder = enumutils.SortOrderDesc | ||
var sladeCode2 enumutils.SortOrder = enumutils.SortOrderAsc | ||
|
||
correctFilters := BranchSortInput{ | ||
Name: &name, | ||
SladeCode: &sladeCode, | ||
} | ||
|
||
failingFilters := BranchSortInput{ | ||
Name: &name, | ||
SladeCode: &sladeCode2, | ||
} | ||
|
||
expectedFilters := url.Values{ | ||
"order_by": []string{"name"}, | ||
"slade_code": []string{"-number"}, | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
filter BranchSortInput | ||
wantValues url.Values | ||
wantError bool | ||
}{ | ||
{ | ||
name: "success building filters", | ||
filter: correctFilters, | ||
wantValues: expectedFilters, | ||
wantError: false, | ||
}, | ||
{ | ||
name: "bad filters", | ||
filter: failingFilters, | ||
wantValues: expectedFilters, | ||
wantError: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
i := &BranchSortInput{ | ||
Name: tt.filter.Name, | ||
SladeCode: tt.filter.SladeCode, | ||
} | ||
if gotValues := i.ToURLValues(); !reflect.DeepEqual(gotValues, tt.wantValues) && !tt.wantError { | ||
t.Errorf("BranchSortInput.ToURLValues() = %v, want %v", gotValues, tt.wantValues) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestBranchFilterInput_ToURLValues(t *testing.T) { | ||
|
||
var ( | ||
search = "somesearch" | ||
sladeCode = "sladecode" | ||
parentOrganizationID = "parentorg" | ||
) | ||
|
||
correctFilters := BranchFilterInput{ | ||
Search: &search, | ||
SladeCode: &sladeCode, | ||
ParentOrganizationID: &parentOrganizationID, | ||
} | ||
|
||
failingFilter := BranchFilterInput{ | ||
Search: &search, | ||
} | ||
|
||
expectedFilters := url.Values{ | ||
"search": []string{search}, | ||
"slade_code": []string{sladeCode}, | ||
"parent": []string{parentOrganizationID}, | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
filter BranchFilterInput | ||
wantValues url.Values | ||
wantError bool | ||
}{ | ||
{ | ||
name: "success transforming url values ", | ||
filter: correctFilters, | ||
wantValues: expectedFilters, | ||
wantError: false, | ||
}, | ||
{ | ||
name: "bad filters", | ||
filter: failingFilter, | ||
wantValues: expectedFilters, | ||
wantError: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
i := &BranchFilterInput{ | ||
Search: tt.filter.Search, | ||
SladeCode: tt.filter.SladeCode, | ||
ParentOrganizationID: tt.filter.ParentOrganizationID, | ||
} | ||
if got := i.ToURLValues(); !reflect.DeepEqual(got, tt.wantValues) && !tt.wantError { | ||
t.Errorf("BranchFilterInput.ToURLValues() = %v, want %v", got, tt.wantValues) | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.