Skip to content

Commit

Permalink
More deletion test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
diamondap committed Jan 26, 2024
1 parent 5fbd8ab commit 76aef55
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
10 changes: 1 addition & 9 deletions pgmodels/generic_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,14 +473,6 @@ func (gf *GenericFile) ActiveDeletionWorkItem() (*WorkItem, error) {
return item, err
}

func (gf *GenericFile) DeletionRequest(workItemID int64) (*DeletionRequestView, error) {
workItem, err := WorkItemByID(workItemID)
if err != nil {
return nil, err
}
return DeletionRequestViewByID(workItem.DeletionRequestID)
}

func (gf *GenericFile) AssertDeletionPreconditions() error {
if gf.State == constants.StateDeleted {
return fmt.Errorf("File is already in deleted state")
Expand All @@ -500,7 +492,7 @@ func (gf *GenericFile) assertDeletionApproved() (*WorkItem, *DeletionRequestView
if common.IsEmptyString(workItem.InstApprover) {
return workItem, nil, fmt.Errorf("Deletion work item is missing institutional approver")
}
deletionRequest, err := gf.DeletionRequest(workItem.ID)
deletionRequest, err := DeletionRequestViewByID(workItem.DeletionRequestID)
if deletionRequest == nil || IsNoRowError(err) {
return workItem, nil, fmt.Errorf("No deletion request for work item %d", workItem.ID)
}
Expand Down
16 changes: 9 additions & 7 deletions pgmodels/generic_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func TestFileDeletionPreConditions(t *testing.T) {
assert.True(t, strings.HasPrefix(err.Error(), "No deletion request for work item"))
testGenericFileDeleteError(t, gf)

testFileDeletionRequest(t, gf, workItem.ID)
testFileDeletionRequest(t, gf, workItem)

// Request not yet approved
err = gf.AssertDeletionPreconditions()
Expand All @@ -285,9 +285,7 @@ func TestFileDeletionPreConditions(t *testing.T) {
testGenericFileDeleteError(t, gf)

// Add approver & test
query := pgmodels.NewQuery().
Where("work_item_id", "=", workItem.ID)
req, err := pgmodels.DeletionRequestGet(query)
req, err := pgmodels.DeletionRequestByID(workItem.DeletionRequestID)
require.Nil(t, err)
require.NotNil(t, req)
require.NotEqual(t, int64(0), req.ID)
Expand All @@ -304,9 +302,9 @@ func TestFileDeletionPreConditions(t *testing.T) {
testGenericFileDeleteSuccess(t, gf)
}

func testFileDeletionRequest(t *testing.T, gf *pgmodels.GenericFile, workItemID int64) {
func testFileDeletionRequest(t *testing.T, gf *pgmodels.GenericFile, workItem *pgmodels.WorkItem) {
// Request doesn't exist yet.
reqView, err := gf.DeletionRequest(workItemID)
reqView, err := pgmodels.DeletionRequestViewByID(workItem.DeletionRequestID)
require.NotNil(t, err)
assert.True(t, pgmodels.IsNoRowError(err))
require.Nil(t, reqView)
Expand All @@ -319,7 +317,11 @@ func testFileDeletionRequest(t *testing.T, gf *pgmodels.GenericFile, workItemID
req.ConfirmedByID = 0
require.Nil(t, req.Save())

reqView, err = gf.DeletionRequest(workItemID)
// Add it to the work item for next test
workItem.DeletionRequestID = req.ID
require.NoError(t, workItem.Save())

reqView, err = pgmodels.DeletionRequestViewByID(req.ID)
require.Nil(t, err)
require.NotNil(t, reqView)
assert.Equal(t, req.ID, reqView.ID)
Expand Down
1 change: 1 addition & 0 deletions pgmodels/intellectual_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ func (obj *IntellectualObject) assertDeletionApproved() (*WorkItem, *DeletionReq
}
deletionRequest, err := DeletionRequestViewByID(workItem.DeletionRequestID)
if deletionRequest == nil || IsNoRowError(err) {
fmt.Println(workItem.ID, workItem.DeletionRequestID)
return workItem, nil, fmt.Errorf("No deletion request for work item %d", workItem.ID)
}
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions pgmodels/intellectual_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pgmodels_test

import (
"fmt"
"os"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -236,7 +235,6 @@ func TestObjInsertAndUpdate(t *testing.T) {
}

func TestAssertObjDeletionPreconditions(t *testing.T) {
os.Setenv("APT_ENV", "test")
defer db.ForceFixtureReload()
obj, err := pgmodels.CreateObjectWithRelations()
require.Nil(t, err)
Expand Down

0 comments on commit 76aef55

Please sign in to comment.