From d96de4f4725df7be2f5211e67411ba3b13c48ac6 Mon Sep 17 00:00:00 2001 From: Saad Ahmed Date: Sun, 24 Dec 2023 04:04:02 +0500 Subject: [PATCH] Add form_test.go with test cases for form creation --- tests/form_test.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/form_test.go diff --git a/tests/form_test.go b/tests/form_test.go new file mode 100644 index 0000000..bf7bcfe --- /dev/null +++ b/tests/form_test.go @@ -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`) +}