Skip to content

Commit

Permalink
Add form_test.go with test cases for form creation
Browse files Browse the repository at this point in the history
  • Loading branch information
SaadAhmedGit committed Dec 23, 2023
1 parent a91d3c0 commit d96de4f
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/form_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package tests

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/SaadAhmedGit/formify/internal/models"
)

var (
dummyForm, _ = createDummyForm()
)

func createDummyForm() (models.Form, error) {
createFormsTable()
dummyForm := models.Form{
Title: "Dummy Form",
Description: "This is a dummy form.",
URL: "dummy-form",
PictureURL: "https://ui-avatars.com/api/?name=DummyUser&background=random&length=1&rounded=true",
Owner: dummyUser.ID,
}

err := models.CreateForm(db, dummyForm)
if err != nil {
return models.Form{}, err
}

dummyForm, _ = models.FindForm(db, dummyForm.URL)
return dummyForm, nil
}

func TestFormCreation(t *testing.T) {

form := models.Form{
Title: "Test Form",
Description: "This is a test form.",
URL: "test-form",
PictureURL: "https://ui-avatars.com/api/?name=JohnDoe&background=random&length=1&rounded=true",
Owner: dummyUser.ID,
}

err := models.CreateForm(db, form)
assert.Nil(t, err)
}

func createFormsTable() {
db.MustExec(models.CREATE_FORMS_TABLE_QUERY)
}

func deleteFormsTable() {
db.MustExec(`DROP TABLE forms`)
}

0 comments on commit d96de4f

Please sign in to comment.