55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
package main
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"os"
|
||
|
|
"strings"
|
||
|
|
"testing"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/descrybe/descrybe-v2/apps/api/internal/billing"
|
||
|
|
"github.com/google/uuid"
|
||
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
||
|
|
)
|
||
|
|
|
||
|
|
// Postman A1 Elkotex fixtures — must not appear on Platform Demo / other tenants.
|
||
|
|
var postmanA1FixtureEANs = []string{"5905575903198", "6970995789942"}
|
||
|
|
|
||
|
|
// Integration: Postman Elkotex fixture EANs must not appear outside A1.
|
||
|
|
func TestA1FixtureEANsIsolatedFromDemo(t *testing.T) {
|
||
|
|
dsn := strings.TrimSpace(os.Getenv("DATABASE_URL"))
|
||
|
|
if dsn == "" {
|
||
|
|
t.Skip("DATABASE_URL not set")
|
||
|
|
}
|
||
|
|
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||
|
|
defer cancel()
|
||
|
|
pg, err := pgxpool.New(ctx, dsn)
|
||
|
|
if err != nil {
|
||
|
|
t.Fatalf("postgres: %v", err)
|
||
|
|
}
|
||
|
|
defer pg.Close()
|
||
|
|
|
||
|
|
var a1ID uuid.UUID
|
||
|
|
err = pg.QueryRow(ctx, `
|
||
|
|
SELECT id FROM companies
|
||
|
|
WHERE legacy_company_id = $1 OR name = $2
|
||
|
|
ORDER BY (legacy_company_id = $1) DESC
|
||
|
|
LIMIT 1`, billing.A1LegacyCompanyID, a1CompanyName).Scan(&a1ID)
|
||
|
|
if err != nil {
|
||
|
|
t.Fatalf("resolve A1: %v (run migrate + seed-a1 first)", err)
|
||
|
|
}
|
||
|
|
|
||
|
|
var otherRaw, otherPP int
|
||
|
|
err = pg.QueryRow(ctx, `
|
||
|
|
SELECT
|
||
|
|
(SELECT COUNT(*) FROM raw_products WHERE company_id <> $1 AND gtin = ANY($2::text[])),
|
||
|
|
(SELECT COUNT(*) FROM processed_products WHERE company_id <> $1 AND product_id = ANY($2::text[]))`,
|
||
|
|
a1ID, postmanA1FixtureEANs).Scan(&otherRaw, &otherPP)
|
||
|
|
if err != nil {
|
||
|
|
t.Fatalf("count other-tenant fixtures: %v", err)
|
||
|
|
}
|
||
|
|
if otherRaw > 0 || otherPP > 0 {
|
||
|
|
t.Fatalf("A1 fixture EANs on non-A1 tenants: raw=%d processed=%d (run seed-a1 -mode backfill-categories or npm run seed:a1)", otherRaw, otherPP)
|
||
|
|
}
|
||
|
|
}
|