Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall committed Nov 15, 2024
1 parent e70ee06 commit 4e4a02f
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 7 deletions.
11 changes: 7 additions & 4 deletions internal/handlers/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ func CheckMyWork(w http.ResponseWriter, r *http.Request) {
if strInSlice(column, requiredFields) {
errors[i] = "Missing value"
}
if col == "Parent Collection" {
model := ColumnValue("ObjectModel", header, row)
if column == "Parent Collection" {
model := ColumnValue("Object Model", header, row)
if model == "Paged Content" {
errors[i] = "Paged content must have a parent collection"
}
}

if col == "Page/Item Parent ID" {
model := ColumnValue("ObjectModel", header, row)
if column == "Page/Item Parent ID" {
model := ColumnValue("Object Model", header, row)
if model == "Page" {
errors[i] = "Pages must have a parent id"
}
Expand All @@ -103,6 +103,7 @@ func CheckMyWork(w http.ResponseWriter, r *http.Request) {
id, err := strconv.Atoi(cell)
if err != nil {
errors[i] = "Must be an integer"
break
}
if column == "Parent Collection" {
url := fmt.Sprintf("https://preserve.lehigh.edu/node/%d?_format=json", id)
Expand Down Expand Up @@ -137,6 +138,7 @@ func CheckMyWork(w http.ResponseWriter, r *http.Request) {
case "Page/Item Parent ID":
if _, ok := uploadIds[cell]; !ok {
errors[i] = "Unknown parent ID"
break
}
id := ColumnValue("Upload ID", header, row)
if cell == id {
Expand All @@ -151,6 +153,7 @@ func CheckMyWork(w http.ResponseWriter, r *http.Request) {
name := strings.Split(c.Name, ":")
if len(name) < 4 {
errors[i] = "Contributor name not in proper format"
break
}
if c.Status != "" || c.Email != "" || c.Institution != "" || c.Orcid != "" {
if name[2] != "person" {
Expand Down
139 changes: 136 additions & 3 deletions internal/handlers/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestCheckMyWork(t *testing.T) {
method: http.MethodPost,
body: [][]string{
{"Title", "Object Model", "Full Title"},
{"Test Title", "Model", "Full Test Title"},
{"foo", "bar", "Full Test Title"},
},
statusCode: http.StatusOK,
response: "{}", // Empty errors map
Expand All @@ -67,7 +67,7 @@ func TestCheckMyWork(t *testing.T) {
method: http.MethodPost,
body: [][]string{
{"Title", "Object Model", "Full Title"},
{"", "Model", "foo"},
{"", "bar", "foo"},
},
statusCode: http.StatusOK,
response: `{"A2":"Missing value"}`,
Expand All @@ -87,11 +87,144 @@ func TestCheckMyWork(t *testing.T) {
method: http.MethodPost,
body: [][]string{
{"Title", "Object Model", "Full Title"},
{"Test Title", "Model", ""},
{"foo", "bar", ""},
},
statusCode: http.StatusOK,
response: `{"C2":"Missing value"}`,
},
{
name: "Missing file",
method: http.MethodPost,
body: [][]string{
{"Title", "Object Model", "Full Title", "File Path"},
{"foo", "bar", "foo", "/tmp/file/does/not/exist"},
},
statusCode: http.StatusOK,
response: `{"D2":"File does not exist in islandora_staging"}`,
},
// Parent Collection and PPI
{
name: "Parent Collection not integer",
method: http.MethodPost,
body: [][]string{
{"Title", "Object Model", "Full Title", "Parent Collection"},
{"foo", "bar", "foo", "NotAnInteger"},
},
statusCode: http.StatusOK,
response: `{"D2":"Must be an integer"}`,
},
{
name: "Parent Collection not found",
method: http.MethodPost,
body: [][]string{
{"Title", "Object Model", "Full Title", "Parent Collection"},
{"foo", "bar", "foo", "0"},
},
statusCode: http.StatusOK,
response: `{"D2":"Could not identify parent collection 0"}`,
},
{
name: "Parent Collection exists",
method: http.MethodPost,
body: [][]string{
{"Title", "Object Model", "Full Title", "Parent Collection"},
{"foo", "bar", "foo", "2"},
},
statusCode: http.StatusOK,
response: `{}`,
},
{
name: "Invalid URL",
method: http.MethodPost,
body: [][]string{
{"Title", "Object Model", "Full Title", "Catalog or ArchivesSpace URL"},
{"foo", "bar", "foo", "invalid-url"},
},
statusCode: http.StatusOK,
response: `{"D2":"Invalid URL"}`,
},
{
name: "Duplicate Upload ID",
method: http.MethodPost,
body: [][]string{
{"Title", "Object Model", "Full Title", "Upload ID"},
{"Test Title 1", "bar", "foo", "123"},
{"Test Title 2", "bar", "foo", "123"},
},
statusCode: http.StatusOK,
response: `{"D3":"Duplicate upload ID"}`,
},
{
name: "Invalid EDTF value",
method: http.MethodPost,
body: [][]string{
{"Title", "Object Model", "Full Title", "Creation Date"},
{"foo", "bar", "foo", "1/2/2022"},
},
statusCode: http.StatusOK,
response: `{"D2":"Invalid EDTF value"}`,
},
{
name: "Invalid DOI",
method: http.MethodPost,
body: [][]string{
{"Title", "Object Model", "Full Title", "DOI"},
{"foo", "bar", "foo", "1.2.3.4"},
},
statusCode: http.StatusOK,
response: `{"D2":"Invalid DOI"}`,
},
{
name: "Unknown Parent ID",
method: http.MethodPost,
body: [][]string{
{"Title", "Object Model", "Full Title", "Page/Item Parent ID", "Upload ID"},
{"foo", "bar", "foo", "123", "456"},
},
statusCode: http.StatusOK,
response: `{"D2":"Unknown parent ID"}`,
},
{
name: "Upload ID equals Parent ID",
method: http.MethodPost,
body: [][]string{
{"Title", "Object Model", "Full Title", "Upload ID", "Page/Item Parent ID"},
{"foo", "bar", "foo", "123", "123"},
},
statusCode: http.StatusOK,
response: `{"E2":"Upload ID and parent ID can not be equal"}`,
},
// Contributor
{
name: "Contributor not in proper format",
method: http.MethodPost,
body: [][]string{
{"Title", "Object Model", "Full Title", "Contributor"},
{"foo", "bar", "foo", `{"name":"bad-format"}`},
},
statusCode: http.StatusOK,
response: `{"D2":"Contributor name not in proper format"}`,
},
{
name: "Paged Content need collection",
method: http.MethodPost,
body: [][]string{
{"Title", "Object Model", "Full Title", "Parent Collection"},
{"foo", "Paged Content", "foo", ""},
},
statusCode: http.StatusOK,
response: `{"D2":"Paged content must have a parent collection"}`,
},
{
name: "Page needs Parent ID",
method: http.MethodPost,
body: [][]string{
{"Title", "Object Model", "Full Title", "Page/Item Parent ID"},
{"foo", "Page", "foo", ""},
},
statusCode: http.StatusOK,
response: `{"D2":"Pages must have a parent id"}`,
},
}

sharedSecret := "foo"
Expand Down

0 comments on commit 4e4a02f

Please sign in to comment.