test(server): add test for adding training date attendee
This commit is contained in:
parent
ee51874892
commit
e4992b4352
1 changed files with 63 additions and 0 deletions
|
|
@ -635,4 +635,67 @@ func TestServer(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("Add training date attendee", func(t *testing.T) {
|
||||||
|
tr := &training.Training{
|
||||||
|
Name: "Testing Training for training date",
|
||||||
|
Description: "This is a test training for training date",
|
||||||
|
Days: 1,
|
||||||
|
Pricing: []training.TrainingPrice{
|
||||||
|
{
|
||||||
|
Amount: decimal.NewFromInt(200),
|
||||||
|
Currency: "EUR",
|
||||||
|
Type: training.OpenTrainingPrice,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = handlers.trainingRepository.Create(tr)
|
||||||
|
|
||||||
|
date := time.Date(2024, time.May, 1, 9, 0, 0, 0, time.UTC)
|
||||||
|
|
||||||
|
td := &training.TrainingDate{
|
||||||
|
Address: "Test Address 123, NYC",
|
||||||
|
Capacity: 12,
|
||||||
|
Date: date,
|
||||||
|
Days: tr.Days,
|
||||||
|
IsOnline: false,
|
||||||
|
Location: "NYC",
|
||||||
|
StartTime: date,
|
||||||
|
Price: money.Price{
|
||||||
|
Amount: decimal.NewFromInt(200),
|
||||||
|
Currency: "EUR",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_ = handlers.trainingDateRepository.Create(tr.ID, td)
|
||||||
|
|
||||||
|
newTrainingDateAttendee := NewTrainingDateAttendee{
|
||||||
|
Name: "John Doe",
|
||||||
|
Email: "john.doe@example.com",
|
||||||
|
Company: "Acme Inc.",
|
||||||
|
Position: "Software Engineer",
|
||||||
|
Phone: "+420 123 456 789",
|
||||||
|
IsStudent: new(bool),
|
||||||
|
}
|
||||||
|
|
||||||
|
rr, _ := doPost(t, app, "/v1/trainings/"+tr.ID.String()+"/dates/"+td.ID.String()+"/attendees", newTrainingDateAttendee)
|
||||||
|
assert.Equal(t, http.StatusCreated, rr.StatusCode)
|
||||||
|
|
||||||
|
var resultTrainingDateAttendee TrainingDateAttendee
|
||||||
|
err := json.NewDecoder(rr.Body).Decode(&resultTrainingDateAttendee)
|
||||||
|
assert.NoError(t, err, "error unmarshalling response")
|
||||||
|
assert.Equal(t, newTrainingDateAttendee.Name, resultTrainingDateAttendee.Name)
|
||||||
|
assert.Equal(t, newTrainingDateAttendee.Email, resultTrainingDateAttendee.Email)
|
||||||
|
assert.Equal(t, newTrainingDateAttendee.Company, resultTrainingDateAttendee.Company)
|
||||||
|
assert.Equal(t, newTrainingDateAttendee.Position, resultTrainingDateAttendee.Position)
|
||||||
|
assert.Equal(t, newTrainingDateAttendee.IsStudent, resultTrainingDateAttendee.IsStudent)
|
||||||
|
assert.Equal(t, newTrainingDateAttendee.Phone, resultTrainingDateAttendee.Phone)
|
||||||
|
|
||||||
|
amount, _ := decimal.NewFromString(resultTrainingDateAttendee.Bill.Amount)
|
||||||
|
|
||||||
|
assert.Equal(t, td.Price.Amount, amount)
|
||||||
|
assert.Equal(t, td.Price.Currency, resultTrainingDateAttendee.Bill.Currency)
|
||||||
|
assert.Equal(t, resultTrainingDateAttendee.HasPaid, false)
|
||||||
|
assert.Equal(t, resultTrainingDateAttendee.HasAttended, false)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue