main

mattermost/focalboard

Last updated at: 29/12/2023 09:40

migration_33_test.go

TLDR

This file contains a test suite for the migration of removing deleted category boards.

Methods

Test33RemoveDeletedCategoryBoards

This method is a test suite for the migration process of removing deleted category boards. It includes three sub-tests: "base case - no data in table", "existing data - 2 soft deleted records", and "existing data - no soft deleted records". Each sub-test sets up the test environment, executes the migration, and verifies the result.

END

package migrationstests

import (
	"testing"

	"github.com/stretchr/testify/require"
)

func Test33RemoveDeletedCategoryBoards(t *testing.T) {
	t.Run("base case - no data in table", func(t *testing.T) {
		th, tearDown := SetupTestHelper(t)
		defer tearDown()
		th.f.MigrateToStep(33)
	})

	t.Run("existing data - 2 soft deleted records", func(t *testing.T) {
		th, tearDown := SetupTestHelper(t)
		defer tearDown()

		th.f.MigrateToStep(32).
			ExecFile("./fixtures/test33_with_deleted_data.sql")

		// cound total records
		var count int
		err := th.f.DB().Get(&count, "SELECT COUNT(*) FROM focalboard_category_boards")
		require.NoError(t, err)
		require.Equal(t, 5, count)

		// now we run the migration
		th.f.MigrateToStep(33)

		// and verify record count again.
		// The soft deleted records should have been removed from the DB now
		err = th.f.DB().Get(&count, "SELECT COUNT(*) FROM focalboard_category_boards")
		require.NoError(t, err)
		require.Equal(t, 3, count)
	})

	t.Run("existing data - no soft deleted records", func(t *testing.T) {
		th, tearDown := SetupTestHelper(t)
		defer tearDown()

		th.f.MigrateToStep(32).
			ExecFile("./fixtures/test33_with_no_deleted_data.sql")

		// cound total records
		var count int
		err := th.f.DB().Get(&count, "SELECT COUNT(*) FROM focalboard_category_boards")
		require.NoError(t, err)
		require.Equal(t, 5, count)

		// now we run the migration
		th.f.MigrateToStep(33)

		// and verify record count again.
		// Since there were no soft-deleted records, nothing should have been
		// deleted from the database.
		err = th.f.DB().Get(&count, "SELECT COUNT(*) FROM focalboard_category_boards")
		require.NoError(t, err)
		require.Equal(t, 5, count)

	})
}