Skip to content

Commit

Permalink
Update Application Assessment test
Browse files Browse the repository at this point in the history
Signed-off-by: Marek Aufart <[email protected]>
  • Loading branch information
aufi committed Dec 13, 2023
1 parent 31e3f51 commit f1692f5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 35 deletions.
17 changes: 17 additions & 0 deletions binding/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,23 @@ func (h *Application) Analysis(id uint) (a Analysis) {
return
}

//
// Create an Application Assessment.
func (h *Application) CreateAssesment(id uint, r *api.Assessment) (err error) {
path := Path(api.AppAssessmentsRoot).Inject(Params{api.ID: id})
err = h.client.Post(path, &r)
return
}

//
// Get Application Assessments.
func (h *Application) GetAssesments(id uint) (list []api.Assessment, err error) {
list = []api.Assessment{}
path := Path(api.AppAssessmentsRoot).Inject(Params{api.ID: id})
err = h.client.Get(path, &list)
return
}

//
// Analysis API.
type Analysis struct {
Expand Down
53 changes: 20 additions & 33 deletions test/api/assessment/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ import (
"fmt"
"testing"

"github.com/konveyor/tackle2-hub/api"
"github.com/konveyor/tackle2-hub/test/assert"
)

func TestAssessmentCRUD(t *testing.T) {
for _, r := range Samples {
t.Run(fmt.Sprintf("%s for application %s", r.Questionnaire.Name, r.Application.Name), func(t *testing.T) {
// Create.
err := Assessment.Create(&r)
if err != nil {
t.Errorf(err.Error())
// Create via parent resource.
if r.Application.Name != "" {
app := api.Application{Name: r.Application.Name}
assert.Must(t, RichClient.Application.Create(&app))
r.Application.ID = app.ID
err := RichClient.Application.CreateAssesment(app.ID, &r)
if err != nil {
t.Errorf(err.Error())
}

}

// Get.
Expand All @@ -25,9 +32,9 @@ func TestAssessmentCRUD(t *testing.T) {
t.Errorf("Different response error. Got %v, expected %v", got, r)
}

// Update.
r.Name = "Updated " + r.Name
r.Required = false
// Update example - select green instead of blue.
r.Sections[0].Questions[0].Answers[2].Selected = false // blue (default)
r.Sections[0].Questions[0].Answers[1].Selected = true // green
err = Assessment.Update(&r)
if err != nil {
t.Errorf(err.Error())
Expand All @@ -37,11 +44,11 @@ func TestAssessmentCRUD(t *testing.T) {
if err != nil {
t.Errorf(err.Error())
}
if got.Name != r.Name {
t.Errorf("Different response error. Got %s, expected %s", got.Name, r.Name)
if got.Sections[0].Questions[0].Answers[2].Selected { // blue not selected
t.Errorf("Different response error. Blue should not be selected.")
}
if got.Required != false {
t.Errorf("Required should be false after update. Got %+v, expected %+v", got, r)
if !got.Sections[0].Questions[0].Answers[1].Selected { // green selected
t.Errorf("Different response error. Green should be selected.")
}

// Delete.
Expand All @@ -54,28 +61,8 @@ func TestAssessmentCRUD(t *testing.T) {
if err == nil {
t.Errorf("Resource exits, but should be deleted: %v", r)
}
})
}
}

func TestAssessmentList(t *testing.T) {
samples := Samples

for name := range samples {
sample := samples[name]
assert.Must(t, Assessment.Create(&sample))
samples[name] = sample
}

got, err := Assessment.List()
if err != nil {
t.Errorf(err.Error())
}
if assert.FlatEqual(got, &samples) {
t.Errorf("Different response error. Got %v, expected %v", got, samples)
}

for _, r := range samples {
assert.Must(t, Assessment.Delete(r.ID))
assert.Must(t, RichClient.Application.Delete(r.Application.ID))
})
}
}
5 changes: 3 additions & 2 deletions test/api/assessment/samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import (

// Set of valid resources for tests and reuse.
var (
Assessment1 = api.Assessment{
ApplicationAssessment1 = api.Assessment{
// Ref resource are created by the test.
Application: &api.Ref{
Name: application.Minimal.Name,
},
Questionnaire: api.Ref{
ID: 1,
Name: questionnaire.Questionnaire1.Name,
},
Sections: []assessment.Section{
Expand Down Expand Up @@ -49,5 +50,5 @@ var (
},
},
}
Samples = []api.Assessment{Assessment1}
Samples = []api.Assessment{ApplicationAssessment1}
)

0 comments on commit f1692f5

Please sign in to comment.