Skip to content

Commit

Permalink
Fix migrationWaves test.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Ortel <[email protected]>
  • Loading branch information
jortel committed Jul 16, 2024
1 parent 5146700 commit 7dc9168
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
19 changes: 18 additions & 1 deletion api/migrationwave.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,28 @@ func (h MigrationWaveHandler) Create(ctx *gin.Context) {
}
m := r.Model()
m.CreateUser = h.CurrentUser(ctx)
result := h.DB(ctx).Create(m)
db := h.DB(ctx).Omit(clause.Associations)
result := db.Create(m)
if result.Error != nil {
_ = ctx.Error(result.Error)
return
}
err = h.DB(ctx).Model(m).Association("Applications").Replace("Applications", m.Applications)
if err != nil {
_ = ctx.Error(err)
return
}
err = h.DB(ctx).Model(m).Association("Stakeholders").Replace("Stakeholders", m.Stakeholders)
if err != nil {
_ = ctx.Error(err)
return
}
err = h.DB(ctx).Model(m).Association("StakeholderGroups").Replace("StakeholderGroups", m.StakeholderGroups)
if err != nil {
_ = ctx.Error(err)
return
}

r.With(m)

h.Respond(ctx, http.StatusCreated, r)
Expand Down
6 changes: 6 additions & 0 deletions test/api/migrationwave/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestMigrationWaveCRUD(t *testing.T) {
}
assert.Must(t, Application.Create(&expectedApp))
createdApps = append(createdApps, expectedApp)
r.Applications[0].ID = expectedApp.ID
}

createdStakeholders := []api.Stakeholder{}
Expand All @@ -28,6 +29,7 @@ func TestMigrationWaveCRUD(t *testing.T) {
}
assert.Must(t, Stakeholder.Create(&expectedStakeholder))
createdStakeholders = append(createdStakeholders, expectedStakeholder)
r.Stakeholders[0].ID = expectedStakeholder.ID
}

createdStakeholderGroups := []api.StakeholderGroup{}
Expand All @@ -38,6 +40,7 @@ func TestMigrationWaveCRUD(t *testing.T) {
}
assert.Must(t, StakeholderGroup.Create(&expectedStakeholderGroup))
createdStakeholderGroups = append(createdStakeholderGroups, expectedStakeholderGroup)
r.StakeholderGroups[0].ID = expectedStakeholderGroup.ID
}

assert.Must(t, MigrationWave.Create(&r))
Expand Down Expand Up @@ -102,6 +105,7 @@ func TestMigrationWaveList(t *testing.T) {
}
assert.Must(t, Application.Create(&expectedApp))
createdApps = append(createdApps, expectedApp)
r.Applications[0].ID = expectedApp.ID
}

for _, stakeholder := range r.Stakeholders {
Expand All @@ -111,6 +115,7 @@ func TestMigrationWaveList(t *testing.T) {
}
assert.Must(t, Stakeholder.Create(&expectedStakeholder))
createdStakeholders = append(createdStakeholders, expectedStakeholder)
r.Stakeholders[0].ID = expectedStakeholder.ID
}

for _, stakeholderGroup := range r.StakeholderGroups {
Expand All @@ -120,6 +125,7 @@ func TestMigrationWaveList(t *testing.T) {
}
assert.Must(t, StakeholderGroup.Create(&expectedStakeholderGroup))
createdStakeholderGroups = append(createdStakeholderGroups, expectedStakeholderGroup)
r.StakeholderGroups[0].ID = expectedStakeholderGroup.ID
}
assert.Must(t, MigrationWave.Create(&r))
createdMigrationWaves = append(createdMigrationWaves, r)
Expand Down
2 changes: 1 addition & 1 deletion test/api/review/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestReviewList(t *testing.T) {

// Delete related reviews and applications.
for _, review := range createdReviews {
assert.Must(t, Application.Delete(review.ID))
assert.Must(t, Application.Delete(review.Application.ID))
assert.Must(t, Review.Delete(review.ID))
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/api/ticket/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestTicketList(t *testing.T) {
// Delete tickets and related resources.
for _, ticket := range createdTickets {
assert.Must(t, Ticket.Delete(ticket.ID))
assert.Must(t, Application.Delete(ticket.ID))
assert.Must(t, Application.Delete(ticket.Application.ID))
}
for _, tracker := range createdTrackers {
assert.Must(t, Tracker.Delete(tracker.ID))
Expand Down

0 comments on commit 7dc9168

Please sign in to comment.