Skip to content

Commit 7511e97

Browse files
author
Zerek.Cheng
committed
Merge remote-tracking branch 'sub2api/main'
# Conflicts: # backend/cmd/server/VERSION
2 parents 10cd7a9 + 6449da6 commit 7511e97

169 files changed

Lines changed: 15305 additions & 1302 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/backend-ci.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ jobs:
2828
working-directory: backend
2929
run: make test-integration
3030

31+
frontend:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v6
35+
- name: Setup pnpm
36+
uses: pnpm/action-setup@v4
37+
with:
38+
version: 9
39+
- name: Setup Node.js
40+
uses: actions/setup-node@v6
41+
with:
42+
node-version: '20'
43+
cache: 'pnpm'
44+
cache-dependency-path: frontend/pnpm-lock.yaml
45+
- name: Install frontend dependencies
46+
working-directory: frontend
47+
run: pnpm install --frozen-lockfile
48+
- name: Frontend typecheck and critical vitest
49+
run: make test-frontend
50+
3151
golangci-lint:
3252
runs-on: ubuntu-latest
3353
steps:
@@ -46,4 +66,4 @@ jobs:
4666
with:
4767
version: v2.9
4868
args: --timeout=30m
49-
working-directory: backend
69+
working-directory: backend

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ backend/cmd/server/server
126126
deploy/docker-compose.override.yml
127127
.gocache/
128128
vite.config.js
129-
docs/
129+
docs/*
130+
!docs/PAYMENT.md
131+
!docs/PAYMENT_CN.md
132+
!docs/ADMIN_PAYMENT_INTEGRATION_API.md
130133
.serena/
131134
.codex/
132135
frontend/coverage/

Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
.PHONY: build build-backend build-frontend build-datamanagementd test test-backend test-frontend test-datamanagementd secret-scan
1+
.PHONY: build build-backend build-frontend build-datamanagementd test test-backend test-frontend test-frontend-critical test-datamanagementd secret-scan
2+
3+
FRONTEND_CRITICAL_VITEST := \
4+
src/views/auth/__tests__/LinuxDoCallbackView.spec.ts \
5+
src/views/auth/__tests__/WechatCallbackView.spec.ts \
6+
src/views/user/__tests__/PaymentView.spec.ts \
7+
src/views/user/__tests__/PaymentResultView.spec.ts \
8+
src/components/user/profile/__tests__/ProfileInfoCard.spec.ts \
9+
src/views/admin/__tests__/SettingsView.spec.ts
210

311
# 一键编译前后端
412
build: build-backend build-frontend
@@ -24,6 +32,10 @@ test-backend:
2432
test-frontend:
2533
@pnpm --dir frontend run lint:check
2634
@pnpm --dir frontend run typecheck
35+
@$(MAKE) test-frontend-critical
36+
37+
test-frontend-critical:
38+
@pnpm --dir frontend exec vitest run $(FRONTEND_CRITICAL_VITEST)
2739

2840
test-datamanagementd:
2941
@cd datamanagement && go test ./...

backend/cmd/server/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.114-3
1+
0.1.115
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package migrate
2+
3+
import (
4+
"testing"
5+
6+
"entgo.io/ent/dialect/entsql"
7+
entschema "entgo.io/ent/dialect/sql/schema"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestAuthIdentityFoundationForeignKeyOnDeleteActions(t *testing.T) {
12+
require.Equal(
13+
t,
14+
entschema.Cascade,
15+
findForeignKeyBySymbol(t, AuthIdentitiesTable, "auth_identities_users_auth_identities").OnDelete,
16+
)
17+
require.Equal(
18+
t,
19+
entschema.Cascade,
20+
findForeignKeyBySymbol(t, AuthIdentityChannelsTable, "auth_identity_channels_auth_identities_channels").OnDelete,
21+
)
22+
require.Equal(
23+
t,
24+
entschema.Cascade,
25+
findForeignKeyBySymbol(t, IdentityAdoptionDecisionsTable, "identity_adoption_decisions_pending_auth_sessions_adoption_decision").OnDelete,
26+
)
27+
28+
require.Equal(
29+
t,
30+
entschema.SetNull,
31+
findForeignKeyBySymbol(t, PendingAuthSessionsTable, "pending_auth_sessions_users_pending_auth_sessions").OnDelete,
32+
)
33+
require.Equal(
34+
t,
35+
entschema.SetNull,
36+
findForeignKeyBySymbol(t, IdentityAdoptionDecisionsTable, "identity_adoption_decisions_auth_identities_adoption_decisions").OnDelete,
37+
)
38+
}
39+
40+
func TestPaymentOrdersOutTradeNoPartialUniqueIndex(t *testing.T) {
41+
idx := findIndexByName(t, PaymentOrdersTable, "paymentorder_out_trade_no")
42+
require.True(t, idx.Unique)
43+
require.Len(t, idx.Columns, 1)
44+
require.Equal(t, "out_trade_no", idx.Columns[0].Name)
45+
require.NotNil(t, idx.Annotation)
46+
require.Equal(t, (&entsql.IndexAnnotation{Where: "out_trade_no <> ''"}).Where, idx.Annotation.Where)
47+
}
48+
49+
func findForeignKeyBySymbol(t *testing.T, table *entschema.Table, symbol string) *entschema.ForeignKey {
50+
t.Helper()
51+
52+
for _, fk := range table.ForeignKeys {
53+
if fk.Symbol == symbol {
54+
return fk
55+
}
56+
}
57+
58+
require.Failf(t, "missing foreign key", "table %s should include foreign key %s", table.Name, symbol)
59+
return nil
60+
}
61+
62+
func findIndexByName(t *testing.T, table *entschema.Table, name string) *entschema.Index {
63+
t.Helper()
64+
65+
for _, idx := range table.Indexes {
66+
if idx.Name == name {
67+
return idx
68+
}
69+
}
70+
71+
require.Failf(t, "missing index", "table %s should include index %s", table.Name, name)
72+
return nil
73+
}

backend/ent/migrate/schema.go

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/ent/schema/auth_identity.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ func (AuthIdentity) Edges() []ent.Edge {
7979
Field("user_id").
8080
Required().
8181
Unique(),
82-
edge.To("channels", AuthIdentityChannel.Type),
82+
edge.To("channels", AuthIdentityChannel.Type).
83+
Annotations(entsql.OnDelete(entsql.Cascade)),
8384
edge.To("adoption_decisions", IdentityAdoptionDecision.Type),
8485
}
8586
}

backend/ent/schema/auth_identity_schema_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package schema
33
import (
44
"testing"
55

6+
"entgo.io/ent"
67
"entgo.io/ent/entc/load"
8+
"entgo.io/ent/schema/field"
79
"github.com/stretchr/testify/require"
810
)
911

@@ -74,6 +76,17 @@ func TestAuthIdentityFoundationSchemas(t *testing.T) {
7476

7577
userSchema := requireSchema(t, schemas, "User")
7678
requireSchemaFields(t, userSchema, "signup_source", "last_login_at", "last_active_at")
79+
signupSource := requireSchemaField(t, userSchema, "signup_source")
80+
require.Equal(t, field.TypeString, signupSource.Info.Type)
81+
require.True(t, signupSource.Default)
82+
require.Equal(t, "email", signupSource.DefaultValue)
83+
require.Equal(t, 1, signupSource.Validators)
84+
85+
validator := requireStringFieldValidator(t, User{}.Fields(), "signup_source")
86+
for _, value := range []string{"email", "linuxdo", "wechat", "oidc"} {
87+
require.NoError(t, validator(value))
88+
}
89+
require.Error(t, validator("github"))
7790
}
7891

7992
func requireSchema(t *testing.T, schemas map[string]*load.Schema, name string) *load.Schema {
@@ -98,6 +111,37 @@ func requireSchemaFields(t *testing.T, schema *load.Schema, names ...string) {
98111
}
99112
}
100113

114+
func requireSchemaField(t *testing.T, schema *load.Schema, name string) *load.Field {
115+
t.Helper()
116+
117+
for _, schemaField := range schema.Fields {
118+
if schemaField.Name == name {
119+
return schemaField
120+
}
121+
}
122+
123+
require.Failf(t, "missing schema field", "schema %s should include field %s", schema.Name, name)
124+
return nil
125+
}
126+
127+
func requireStringFieldValidator(t *testing.T, fields []ent.Field, name string) func(string) error {
128+
t.Helper()
129+
130+
for _, entField := range fields {
131+
descriptor := entField.Descriptor()
132+
if descriptor.Name != name {
133+
continue
134+
}
135+
require.NotEmpty(t, descriptor.Validators, "field %s should include a validator", name)
136+
validator, ok := descriptor.Validators[0].(func(string) error)
137+
require.True(t, ok, "field %s validator should be func(string) error", name)
138+
return validator
139+
}
140+
141+
require.Failf(t, "missing field validator", "schema should include field %s", name)
142+
return nil
143+
}
144+
101145
func requireHasUniqueIndex(t *testing.T, schema *load.Schema, fields ...string) {
102146
t.Helper()
103147

backend/ent/schema/payment_order.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ func (PaymentOrder) Edges() []ent.Edge {
185185

186186
func (PaymentOrder) Indexes() []ent.Index {
187187
return []ent.Index{
188-
index.Fields("out_trade_no"),
188+
index.Fields("out_trade_no").
189+
Unique().
190+
Annotations(entsql.IndexWhere("out_trade_no <> ''")),
189191
index.Fields("user_id"),
190192
index.Fields("status"),
191193
index.Fields("expires_at"),

backend/ent/schema/pending_auth_session.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ func (PendingAuthSession) Edges() []ent.Edge {
119119
Field("target_user_id").
120120
Unique(),
121121
edge.To("adoption_decision", IdentityAdoptionDecision.Type).
122+
Annotations(entsql.OnDelete(entsql.Cascade)).
122123
Unique(),
123124
}
124125
}

0 commit comments

Comments
 (0)