go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/projects/kana-server/pkg/model/main_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2023 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package model_test
     9  
    10  import (
    11  	"context"
    12  	"testing"
    13  
    14  	"go.charczuk.com/sdk/apputil"
    15  	"go.charczuk.com/sdk/assert"
    16  	"go.charczuk.com/sdk/db"
    17  	"go.charczuk.com/sdk/logutil"
    18  	"go.charczuk.com/sdk/testutil"
    19  
    20  	"go.charczuk.com/projects/kana-server/pkg/model"
    21  	"go.charczuk.com/projects/kana-server/pkg/types"
    22  )
    23  
    24  func TestMain(m *testing.M) {
    25  	testutil.New(m,
    26  		testutil.OptWithDefaultDB(
    27  			db.OptLog(logutil.New()),
    28  		),
    29  		testutil.OptBefore(
    30  			func(ctx context.Context) error {
    31  				return model.Migrations().Apply(ctx, testutil.DefaultDB())
    32  			},
    33  		),
    34  	).Run()
    35  }
    36  
    37  // CreateTestQuiz creates a test quiz.
    38  func CreateTestQuiz(t *testing.T, mgr *apputil.ModelManager, user *apputil.User) *types.Quiz {
    39  	q0 := types.NewTestQuiz(user.ID)
    40  	assert.ItsNil(t, mgr.Invoke(context.Background()).Create(q0))
    41  
    42  	q0r0 := types.NewTestQuizResultCorrect(q0)
    43  	assert.ItsNil(t, mgr.Invoke(context.Background()).Create(q0r0))
    44  	q0r1 := types.NewTestQuizResultCorrect(q0)
    45  	assert.ItsNil(t, mgr.Invoke(context.Background()).Create(q0r1))
    46  	q0r2 := types.NewTestQuizResultCorrect(q0)
    47  	assert.ItsNil(t, mgr.Invoke(context.Background()).Create(q0r2))
    48  	q0r3 := types.NewTestQuizResultIncorrect(q0)
    49  	assert.ItsNil(t, mgr.Invoke(context.Background()).Create(q0r3))
    50  	q0r4 := types.NewTestQuizResultCorrect(q0)
    51  	assert.ItsNil(t, mgr.Invoke(context.Background()).Create(q0r4))
    52  	q0r5 := types.NewTestQuizResultCorrect(q0)
    53  	assert.ItsNil(t, mgr.Invoke(context.Background()).Create(q0r5))
    54  	q0r6 := types.NewTestQuizResultIncorrect(q0)
    55  	assert.ItsNil(t, mgr.Invoke(context.Background()).Create(q0r6))
    56  	return q0
    57  }