review
This commit is contained in:
parent
6ffc0d2c99
commit
6153017b62
22 changed files with 835 additions and 100 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/danyel/go-guess/backend/internal/database/repository"
|
||||
"github.com/danyel/go-guess/backend/internal/service/model"
|
||||
)
|
||||
|
||||
|
|
@ -17,8 +18,9 @@ type fakeStore struct {
|
|||
|
||||
type invitationStore struct {
|
||||
*fakeStore
|
||||
interview model.Interview
|
||||
saved bool
|
||||
interview model.Interview
|
||||
invitations []model.Invitation
|
||||
saved bool
|
||||
}
|
||||
|
||||
func (f *invitationStore) CreateInvitation(_ context.Context, value model.Invitation) (model.Invitation, error) {
|
||||
|
|
@ -32,6 +34,9 @@ func (f *invitationStore) SaveAnswer(context.Context, string, uint, string) erro
|
|||
f.saved = true
|
||||
return nil
|
||||
}
|
||||
func (f *invitationStore) ListInvitations(context.Context, uint) ([]model.Invitation, error) {
|
||||
return f.invitations, nil
|
||||
}
|
||||
|
||||
func (f *fakeStore) FindUserByEmail(context.Context, string) (model.User, error) {
|
||||
return model.User{}, errors.New("unused")
|
||||
|
|
@ -179,4 +184,26 @@ func TestQuestionReferenceAnswerValidation(t *testing.T) {
|
|||
if question.ReferenceAnswer != "" || question.Options[0] != "One" {
|
||||
t.Fatalf("unexpected normalized question: %#v", question)
|
||||
}
|
||||
|
||||
if _, err := service.Create(context.Background(), model.Question{
|
||||
Text: "Review this change", Type: "code_review", ReferenceAnswer: "Spot the race",
|
||||
}); !errors.Is(err, ErrInvalidQuestion) {
|
||||
t.Fatalf("expected missing code snippet error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvitationReviewIsScopedToJob(t *testing.T) {
|
||||
store := &invitationStore{
|
||||
fakeStore: &fakeStore{},
|
||||
invitations: []model.Invitation{{ID: 3, JobID: 8, Token: "opaque-token"}},
|
||||
interview: model.Interview{Invitation: model.Invitation{ID: 3, JobID: 8}},
|
||||
}
|
||||
service := NewInvitationService(store, "")
|
||||
review, err := service.Review(context.Background(), 8, 3)
|
||||
if err != nil || review.Invitation.ID != 3 {
|
||||
t.Fatalf("expected invitation review, got %#v, %v", review, err)
|
||||
}
|
||||
if _, err := service.Review(context.Background(), 8, 4); !errors.Is(err, repository.ErrNotFound) {
|
||||
t.Fatalf("expected missing invitation error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue