Skip to content

Commit

Permalink
Increase integration test for applications repo methods. (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
sudiptob2 authored Dec 19, 2024
1 parent bef1a68 commit 9ebbdf2
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions internal/database/repository/application_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,39 @@ func (as *ApplicationIntTest) TearDownSuite() {
as.pool.Close()
}

func (as *ApplicationIntTest) TestGetApplicationByID() {
ctx := context.Background()
tests := []struct {
name string
id string
expected bool
}{
{
name: "Get Application by ID",
id: "1",
expected: true,
},
{
name: "Get Application by ID that does not exist",
id: "100",
expected: false,
},
}

for _, tt := range tests {
as.Run(tt.name, func() {
app, err := as.repo.GetApplicationByID(ctx, tt.id)
if tt.expected {
require.NoError(as.T(), err)
assert.Equal(as.T(), tt.id, app.ID)
} else {
require.Error(as.T(), err)
assert.Nil(as.T(), app)
}
})
}
}

func (as *ApplicationIntTest) TestGetAllApplications() {
ctx := context.Background()
tests := []struct {
Expand Down Expand Up @@ -216,6 +249,38 @@ func (as *ApplicationIntTest) TestUpdateApplication() {
}
}

func (as *ApplicationIntTest) TestDeleteApplicationsNotInIDs() {
ctx := context.Background()
tests := []struct {
name string
ids []string
expectCount int
}{
{
name: "Delete Applications not in IDs",
ids: []string{"1", "2", "3"},
expectCount: 3,
},
}
deletedAtNano := time.Now().UnixNano()

for _, tt := range tests {
as.Run(tt.name, func() {
err := as.repo.DeleteApplicationsNotInIDs(ctx, tt.ids, deletedAtNano)
require.NoError(as.T(), err)

query := `SELECT COUNT(id) FROM applications WHERE deleted_at_nano IS NULL`
var count int
err = as.repo.dbpool.QueryRow(ctx, query).Scan(&count)

require.NoError(as.T(), err)
assert.Equal(as.T(), tt.expectCount, count)

})
}

}

func seedApplications(ctx context.Context, t *testing.T, repo *PostgresRepository) {
t.Helper()

Expand Down

0 comments on commit 9ebbdf2

Please sign in to comment.