package filedb

import (
	"encoding/json"
	"gadmin/internal/admin/forms"
	"leafstalk/log"
	"testing"
)

func TestNewCollection(t *testing.T) {
	db1 := NewCollection("email.db")
	db1.Add(&forms.EmailItem{Title: "aaaaaaaaaa"})
	db1.Add(&forms.EmailItem{Title: "aaaaaaaaaa1"})
	db1.Add(&forms.EmailItem{Title: "aaaaaaaaaa2"})
	db1.Add(&forms.EmailItem{Title: "aaaaaaaaaa3"})
	db1.Add(&forms.EmailItem{Title: "aaaaaaaaaa4"})
	db1.Add(&forms.EmailItem{Title: "aaaaaaaaa5a"})

	emails, err := db1.All()
	log.Info(err)
	data, _ := json.Marshal(emails)
	log.Errorln(string(data))

	db1.Remove(6)
	emails2, _ := db1.All()

	data2, _ := json.Marshal(emails2)
	log.Errorln(string(data2))
	err = db1.SaveDb()
	log.Errorln(err)
	db2 := NewCollection("email")
	err = db2.LoadDb()
	log.Errorln(err)
}
