-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add form_test.go with test cases for form creation
- Loading branch information
1 parent
a91d3c0
commit d96de4f
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`) | ||
} |