Files
hnh-map/internal/app/services/export_test.go
Nikolay Tatarinov 8f769543f4 Refactor frontend components and enhance API integration
- Updated frontend-nuxt.mdc to specify usage of composables for API calls.
- Added new AuthCard and ConfirmModal components for improved UI consistency.
- Introduced UserAvatar component for user profile display, replacing previous Gravatar implementation.
- Implemented useFormSubmit composable for handling form submissions with loading and error states.
- Enhanced vitest.config.ts to include coverage reporting for composables and components.
- Removed deprecated useAdminApi and useAuth composables to streamline API interactions.
- Updated login and setup pages to utilize new components and composables for better user experience.
2026-03-04 00:14:05 +03:00

65 lines
1.6 KiB
Go

package services_test
import (
"bytes"
"context"
"encoding/json"
"testing"
"github.com/andyleap/hnh-map/internal/app"
"github.com/andyleap/hnh-map/internal/app/services"
"github.com/andyleap/hnh-map/internal/app/store"
"go.etcd.io/bbolt"
)
func newTestExportService(t *testing.T) (*services.ExportService, *store.Store) {
t.Helper()
db := newTestDB(t)
st := store.New(db)
mapSvc := services.NewMapService(services.MapServiceDeps{
Store: st,
GridStorage: t.TempDir(),
GridUpdates: &app.Topic[app.TileData]{},
})
return services.NewExportService(st, mapSvc), st
}
func TestExport_EmptyDB(t *testing.T) {
export, _ := newTestExportService(t)
var buf bytes.Buffer
err := export.Export(context.Background(), &buf)
if err != nil {
t.Fatal(err)
}
if buf.Len() == 0 {
t.Fatal("expected non-empty zip output")
}
// ZIP magic number
if buf.Len() < 4 || buf.Bytes()[0] != 0x50 || buf.Bytes()[1] != 0x4b {
t.Fatal("expected valid zip header")
}
}
func TestExport_WithGrid(t *testing.T) {
export, st := newTestExportService(t)
ctx := context.Background()
gd := app.GridData{ID: "g1", Map: 1, Coord: app.Coord{X: 0, Y: 0}}
gdRaw, _ := json.Marshal(gd)
mi := app.MapInfo{ID: 1, Name: "test", Hidden: false}
miRaw, _ := json.Marshal(mi)
st.Update(ctx, func(tx *bbolt.Tx) error {
if err := st.PutGrid(tx, "g1", gdRaw); err != nil {
return err
}
return st.PutMap(tx, 1, miRaw)
})
var buf bytes.Buffer
err := export.Export(ctx, &buf)
if err != nil {
t.Fatal(err)
}
if buf.Len() < 4 {
t.Fatal("expected zip data")
}
}