Added Identity Image Database delete

This commit is contained in:
Samuel Hawksby-Robinson 2020-10-27 14:33:27 +00:00 committed by Andrea Maria Piana
parent daa5ca1dbd
commit 7ea153bae1
2 changed files with 28 additions and 29 deletions

View File

@ -95,6 +95,11 @@ func (d *Database) StoreIdentityImages(iis []IdentityImage) (err error) {
return
}
func (d *Database) DeleteIdentityImage(it string) error {
_, err := d.db.Exec(`DELETE FROM identity_images WHERE type = ?`, it)
return err
}
func (i IdentityImage) GetDataURI() (string, error) {
mt, err := GetMimeType(i.Payload)
if err != nil {

View File

@ -23,10 +23,7 @@ func setupTestDB(t *testing.T) (Database, func()) {
}
}
func TestDatabase_GetIdentityImages(t *testing.T) {
db, stop := setupTestDB(t)
defer stop()
func seedTestDB(t *testing.T, db Database) {
iis := []IdentityImage{
{
Type: "thumbnail",
@ -45,10 +42,16 @@ func TestDatabase_GetIdentityImages(t *testing.T) {
ResizeTarget: 240,
},
}
expected := `[{"type":"large","uri":"data:image/png;base64,iVBORw0KGgoAAAANSUg=","width":240,"height":300,"file_size":1024,"resize_target":240},{"type":"thumbnail","uri":"data:image/jpeg;base64,/9j/2wCEAFA3PEY8MlA=","width":80,"height":80,"file_size":256,"resize_target":80}]`
err := db.StoreIdentityImages(iis)
require.NoError(t, err)
require.NoError(t, db.StoreIdentityImages(iis))
}
func TestDatabase_GetIdentityImages(t *testing.T) {
db, stop := setupTestDB(t)
defer stop()
seedTestDB(t, db)
expected := `[{"type":"large","uri":"data:image/png;base64,iVBORw0KGgoAAAANSUg=","width":240,"height":300,"file_size":1024,"resize_target":240},{"type":"thumbnail","uri":"data:image/jpeg;base64,/9j/2wCEAFA3PEY8MlA=","width":80,"height":80,"file_size":256,"resize_target":80}]`
oiis, err := db.GetIdentityImages()
require.NoError(t, err)
@ -61,25 +64,7 @@ func TestDatabase_GetIdentityImages(t *testing.T) {
func TestDatabase_GetIdentityImage(t *testing.T) {
db, stop := setupTestDB(t)
defer stop()
iis := []IdentityImage{
{
Type: "thumbnail",
Payload: testJpegBytes,
Width: 80,
Height: 80,
FileSize: 256,
ResizeTarget: 80,
},
{
Type: "large",
Payload: testPngBytes,
Width: 240,
Height: 300,
FileSize: 1024,
ResizeTarget: 240,
},
}
seedTestDB(t, db)
cs := []struct{
Name string
@ -95,9 +80,6 @@ func TestDatabase_GetIdentityImage(t *testing.T) {
},
}
err := db.StoreIdentityImages(iis)
require.NoError(t, err)
for _, c := range cs {
oii, err := db.GetIdentityImage(c.Name)
require.NoError(t, err)
@ -108,6 +90,18 @@ func TestDatabase_GetIdentityImage(t *testing.T) {
}
}
func TestDatabase_DeleteIdentityImage(t *testing.T) {
db, stop := setupTestDB(t)
defer stop()
seedTestDB(t, db)
require.NoError(t, db.DeleteIdentityImage("thumbnail"))
oii, err := db.GetIdentityImage("thumbnail")
require.NoError(t, err)
require.Empty(t, oii)
}
func TestIdentityImage_GetDataURI(t *testing.T) {
cs := []struct{
II IdentityImage