Skip to content

Commit

Permalink
Performance improvements, bug fixes, and test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Wil Simpson committed Mar 20, 2024
1 parent 3d6a8bd commit 7773bea
Show file tree
Hide file tree
Showing 9 changed files with 1,825 additions and 489 deletions.
976 changes: 749 additions & 227 deletions coverage.out

Large diffs are not rendered by default.

132 changes: 124 additions & 8 deletions pkg/mocks/gamebackend_s_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkg/repository/character_r_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ var _ = Describe("Character repository", func() {

Describe("FindAll", func() {
findAll := (func(ctx context.Context) {
_, err := characterRepo.Create(ctx, &model.Character{
OwnerId: faker.Username(),
Name: faker.Username(),
Gender: "Male",
Realm: "Human",
})
Expect(err).NotTo(HaveOccurred())
all, err := characterRepo.FindAll(ctx)
Expect(err).NotTo(HaveOccurred())
Expect(len(all) >= 1).To(BeTrue())
Expand Down
34 changes: 7 additions & 27 deletions pkg/repository/gamebackend_r.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type dimensionRepository interface {
version string,
mapIds []*uuid.UUID,
) (*model.Dimension, error)
DuplicateDimension(ctx context.Context, refId *uuid.UUID, name string) (*model.Dimension, error)
FindDimensionByName(ctx context.Context, name string) (*model.Dimension, error)
FindDimensionById(ctx context.Context, id *uuid.UUID) (*model.Dimension, error)
FindDimensionsByNames(ctx context.Context, names []string) (model.Dimensions, error)
Expand Down Expand Up @@ -174,8 +173,8 @@ func (r *gamebackendRepository) CreateMap(
return newMap, nil
}

// DeleteDimensionById implements GamebackendRepository.
func (r *gamebackendRepository) DeleteDimensionById(ctx context.Context, id *uuid.UUID) error {
// DeleteDimension implements GamebackendRepository.
func (r *gamebackendRepository) DeleteDimension(ctx context.Context, id *uuid.UUID) error {
return r.DB.WithContext(ctx).Delete(&model.Dimension{}, id).Error
}

Expand All @@ -184,6 +183,11 @@ func (r *gamebackendRepository) DeleteDimensionByName(ctx context.Context, name
return r.DB.WithContext(ctx).Delete(&model.Dimension{}, "name = ?", name).Error
}

// DeleteDimensionById implements GamebackendRepository.
func (r *gamebackendRepository) DeleteDimensionById(ctx context.Context, id *uuid.UUID) error {
return r.DB.WithContext(ctx).Delete(&model.Dimension{}, "id = ?", id.String()).Error
}

// DeleteMapById implements GamebackendRepository.
func (r *gamebackendRepository) DeleteMapById(ctx context.Context, id *uuid.UUID) error {
return r.DB.WithContext(ctx).Delete(&model.Map{}, id).Error
Expand All @@ -194,30 +198,6 @@ func (r *gamebackendRepository) DeleteMapByName(ctx context.Context, name string
return r.DB.WithContext(ctx).Delete(&model.Map{}, "name = ?", name).Error
}

// DuplicateDimension implements GamebackendRepository.
func (r *gamebackendRepository) DuplicateDimension(
ctx context.Context,
refId *uuid.UUID,
name string,
) (*model.Dimension, error) {
dimension, err := r.FindDimensionById(ctx, refId)
if err != nil {
return nil, err
}

if dimension == nil {
return nil, model.ErrDoesNotExist
}

dimension.Id = nil
dimension.Name = name
if err = r.DB.WithContext(ctx).Preload(clause.Associations).Create(&dimension).Error; err != nil {
return nil, err
}

return dimension, nil
}

// SaveDimension implements GamebackendRepository.
func (r *gamebackendRepository) SaveDimension(
ctx context.Context,
Expand Down
39 changes: 0 additions & 39 deletions pkg/repository/gamebackend_r_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,45 +177,6 @@ var _ = Describe("Gamebackend repository", func() {
})
})

Describe("DuplicateDimesnion", func() {
When("given valid input", func() {
It("should work", func() {
_, dimension, _ := createModels()
out, err := gamebackendRepo.DuplicateDimension(nil, dimension.Id, dimension.Name+"a")
Expect(err).NotTo(HaveOccurred())
Expect(out).NotTo(BeNil())
Expect(out.Id).NotTo(BeNil())
Expect(out.Name).To(Equal(dimension.Name + "a"))

out, err = gamebackendRepo.FindDimensionByName(nil, dimension.Name+"a")
Expect(err).NotTo(HaveOccurred())
Expect(out).NotTo(BeNil())

out2, err := gamebackendRepo.FindDimensionByName(nil, dimension.Name)
Expect(err).NotTo(HaveOccurred())
Expect(out).NotTo(BeNil())

Expect(out.Id).NotTo(BeEquivalentTo(out2.Id))
})
})

When("given invalid input", func() {
It("should error when given dimension doesn't exist", func() {
id, err := uuid.NewRandom()
Expect(err).NotTo(HaveOccurred())

_, dimension, _ := createModels()
out, err := gamebackendRepo.DuplicateDimension(nil, &id, dimension.Name+"a")
Expect(err).To(MatchError(model.ErrDoesNotExist))
Expect(out).To(BeNil())

out, err = gamebackendRepo.FindDimensionByName(nil, dimension.Name+"a")
Expect(err).NotTo(HaveOccurred())
Expect(out).To(BeNil())
})
})
})

Describe("SaveDimension", func() {
When("given valid input", func() {
It("should work", func() {
Expand Down
Loading

0 comments on commit 7773bea

Please sign in to comment.