Backend : token_version (000022, claim tv, 401 si révoqué, bump au password — fin limite V1), quota (000023 idempotente, colonne héritée de 000001, 413 QUOTA_EXCEEDED, GET /users/me/usage), devices (GET + DELETE révocation, EnforceDeviceExists en prod), renames concurrents transparents (baseUpdatedAt + conflicts[] non-fataux, tolérance 2 s). Tests service + handlers + migrations + auth. Mobile : pipeline conflits (DTO + SyncConflictStore + worker + dialogue), baseUpdatedAt prêt, liens 7j par défaut, écran Appareils (+ quota), import classeur unifié (scan/note/dossier), onboarding cercle Famille. Contrat docs/api-v1.md, V3.md (S6 livré).
84 lines
2.7 KiB
Go
84 lines
2.7 KiB
Go
package service
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/kazier/backend/repository"
|
|
)
|
|
|
|
// TestRenameConflictReporting : un rename avec baseUpdatedAt périmée
|
|
// s'applique quand même (LWW) mais est signalé en conflicts[] (S6 A4) ;
|
|
// avec une base fraîche, aucun signalement.
|
|
func TestRenameConflictReporting(t *testing.T) {
|
|
s := newServiceStore(t)
|
|
userID := mustCreateUser(t, s.Repository, "conflict-user")
|
|
deviceA := mustRegisterDevice(t, s.Repository, "c0000000000000000000000000000001")
|
|
fileID := repository.NewID()
|
|
if err := s.Repository.Resources.InsertFile(userID, fileID, "origine.txt", "", 0, nil, nil); err != nil {
|
|
t.Fatalf("insert: %v", err)
|
|
}
|
|
|
|
// Base fraîche : pas de conflit.
|
|
name, ms, err := s.Repository.Resources.LiveNameAndUpdatedAt(fileID)
|
|
if err != nil || name != "origine.txt" {
|
|
t.Fatalf("live: %q %d %v", name, ms, err)
|
|
}
|
|
res, err := s.ApplyBatch(userID, deviceA, []SyncOperation{
|
|
syncOp(repository.NewID(), fileID, OpUpdateMetadata, "file", map[string]any{
|
|
"name": "v2.txt", "baseUpdatedAt": ms,
|
|
}),
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("apply: %v", err)
|
|
}
|
|
if res.Applied != 1 || res.Failed != nil || len(res.Conflicts) != 0 {
|
|
t.Fatalf("rename frais doit être silencieux: %+v", res)
|
|
}
|
|
|
|
// Base périmée (concurrent théorique entre-temps) : appliqué + signalé.
|
|
stale := ms - 60_000
|
|
res, err = s.ApplyBatch(userID, deviceA, []SyncOperation{
|
|
syncOp(repository.NewID(), fileID, OpUpdateMetadata, "file", map[string]any{
|
|
"name": "v3.txt", "baseUpdatedAt": stale,
|
|
}),
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("apply: %v", err)
|
|
}
|
|
if res.Applied != 1 || res.Failed != nil {
|
|
t.Fatalf("rename concurrent doit s'appliquer (LWW): %+v", res)
|
|
}
|
|
if len(res.Conflicts) != 1 {
|
|
t.Fatalf("conflit manquant: %+v", res)
|
|
}
|
|
c := res.Conflicts[0]
|
|
if c.ResourceID != fileID || c.ServerName != "v3.txt" || c.ServerUpdatedAt <= 0 {
|
|
t.Fatalf("conflit inattendu: %+v", c)
|
|
}
|
|
|
|
// Sans base (vieux client) : appliqué, jamais signalé.
|
|
res, err = s.ApplyBatch(userID, deviceA, []SyncOperation{
|
|
syncOp(repository.NewID(), fileID, OpUpdateMetadata, "file", map[string]any{"name": "v4.txt"}),
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("apply: %v", err)
|
|
}
|
|
if res.Applied != 1 || res.Failed != nil || len(res.Conflicts) != 0 {
|
|
t.Fatalf("sans base : silencieux: %+v", res)
|
|
}
|
|
|
|
// Tolérance 2 s : un écart d'1 s (skew/troncation) n'est pas un conflit.
|
|
_, nowMs, _ := s.Repository.Resources.LiveNameAndUpdatedAt(fileID)
|
|
res, err = s.ApplyBatch(userID, deviceA, []SyncOperation{
|
|
syncOp(repository.NewID(), fileID, OpUpdateMetadata, "file", map[string]any{
|
|
"name": "v5.txt", "baseUpdatedAt": nowMs - 1000,
|
|
}),
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("apply: %v", err)
|
|
}
|
|
if len(res.Conflicts) != 0 {
|
|
t.Fatalf("écart 1 s ne doit pas signaler: %+v", res)
|
|
}
|
|
}
|