Skip to content

Commit 73a5239

Browse files
authored
refactor(apiv1): accounts api (#825)
* list account and create account * deleteaccount (wip) * remove old accounts code * fix from merge * remove serve method from makefile * ListAccounts, password hash on domain * make lint * more permissive assertion * rename test * update account * Authorization * updated api calls * apis, pointers, auth * swagger * stylecheck * domain validation * tests * swagger * error handling * fix system account changes * Cleanup database interface * test cleanup * fixed nil references * feat: Add logout endpoint to auth routes * feat: Add logoutHandler for stateless JWT token logout * fixed some bug catched in tests * auth/account patch * prettier * remove test logs * fixed incorrect number of parameters * fixed swagger docs * enable swagger in dev environment * errors.Wrap -> fmt.Errorf * test: Add comprehensive test cases for accounts API handlers * fix: Resolve test failures in accounts_test.go * test: Add tests for duplicate username handling in account creation and update * feat: Add username uniqueness checks for account creation and update refactor: Improve username existence checks in SQLite account methods * linted * test: Add comprehensive tests for auth domain token and credential validation * test: Add comprehensive test cases for auth domain token creation and validation * test: Add comprehensive error handling test cases for accounts domain * refactor: Remove `SaveAccountSettings` method from database implementations * test: Add test cases for password update functionality * test(e2e): auth login * lint * send regular context to domain * fixed e2e auth tests * test: Add auth_test.go for end-to-end authentication testing * feat: Add comprehensive authentication tests using Playwright and testcontainers * fix: Handle multiple return values in Playwright test methods * error message * e2e playwrigth tests * ci: setup playwrigth * refactor: Update Playwright tests to use locator-based API * refactor: Remove unnecessary alias for playwright-go expect import * refactor: Replace deprecated expect package with WaitFor() method in Playwright tests * fix: Resolve linting issues in e2e Playwright tests * remove npm ci from e2e ci * make playwright available in path * typo * re enabled ci * base e2e accounts test * more account e2e * feat: Add HTML test reporter with screenshots and detailed results * feat: Embed screenshots as base64 in HTML test report * refactor: Remove GitHub step summary functionality from test helper * refactor: Make reporter global to share test results across test helpers * refactor: Add HandleSuccess method to TestHelper for consistent test result reporting * feat: Add descriptive messages to all test assertions in TestHelper * test: Add descriptive messages to assertions in accounts_test.go * test: Add descriptive error messages to assertions in accounts_test.go * feat: Add descriptive messages to assertions in accounts_test.go * refactor: Update assertion functions to receive *testing.T as first argument * refactor: Update accounts_test.go assertions to pass *testing.T argument * refactor: Update accounts_test.go assertions to use *testing.T argument * refactor: Update `accounts_test.go` to use `*testing.T` argument in `Require()` calls * refactor: Update `th.Require()` calls with `t *testing.T` argument in accounts_test.go * assert helper * refactor: Refactor `False` test helper to use `Assert` function consistently * refactor: Refactor `Equal` test helper to use `Assert` function * refactor: Simplify Error test helper to use Assert function * refactor: Refactor `NoError` to use `Assert` function for consistent error handling * typo * refactor: Differentiate between test cases and assertions in reporter * refactor: Simplify AddResult method signature and use error message for assertion * refactor: Simplify test report with focused failure details and screenshots * refactor: Ensure assertions are always called in PlaywrightRequire helper methods * refactor: Update test error messages to be action-oriented * refactor: Update error messages to be more action-oriented in accounts_test.go * refactor: Update error messages to be action-oriented in accounts_test.go * refactor: Improve error messages in auth_test.go for better test readability * refactor: Improve screenshot handling and test result reporting in Playwright test helper * fix: Improve test reporting with detailed error messages and logging * refactor: Remove unused runningInCI field from TestHelper struct * fix: Improve message formatting in Assert method for better reporting * assertions * test: Add `Require()` calls to 007 test for improved error handling * refactor: Update test reporter to include error details and improve HTML rendering * fix: Properly escape and render base64 screenshot in HTML report * fix: Correct base64 screenshot rendering in test reporter * fixed tests + html report * feat: Add artifact upload for e2e test report * make lint * chore: use correct version in user agent * ci: run e2e after other checks * chore: remove pre-commit
1 parent 07819b5 commit 73a5239

Some content is hidden

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

67 files changed

+3816
-1038
lines changed

.githooks/pre-commit

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/workflows/_e2e.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,17 @@ jobs:
1515
with:
1616
go-version-file: ./go.mod
1717

18+
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.2
19+
20+
- name: Install browsers
21+
run: npx playwright install --with-deps
22+
1823
- run: make e2e
24+
25+
- name: Upload test report
26+
if: always()
27+
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
28+
with:
29+
name: e2e-test-report
30+
path: e2e-report.html
31+
if-no-files-found: ignore

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
# Exclude development data
1212
/dev-data*
1313

14-
# Coverage data
14+
# Tests
1515
/coverage.*
16+
e2e-report.html
1617

1718
# Dist files
1819
dist/

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ clean:
5959

6060
## Runs server for local development
6161
.PHONY: run-server
62-
run-server:
63-
GIN_MODE=$(GIN_MODE) SHIORI_DEVELOPMENT=$(SHIORI_DEVELOPMENT) SHIORI_DIR=$(SHIORI_DIR) SHIORI_HTTP_SECRET_KEY=shiori go run main.go server --log-level debug
62+
run-server: generate
63+
GIN_MODE=$(GIN_MODE) SHIORI_DEVELOPMENT=$(SHIORI_DEVELOPMENT) SHIORI_DIR=$(SHIORI_DIR) SHIORI_HTTP_SECRET_KEY=shiori SHIORI_HTTP_SERVE_SWAGGER=true go run main.go server --log-level debug
6464

6565
## Generate swagger docs
6666
.PHONY: swagger
@@ -134,6 +134,6 @@ coverage:
134134
$(GO) tool cover -html=coverage.txt
135135

136136
## Run generate accross the project
137-
.PHONY: generated
137+
.PHONY: generate
138138
generate:
139139
$(GO) generate ./...

docs/swagger/docs.go

Lines changed: 174 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,124 @@ const docTemplate = `{
1515
"host": "{{.Host}}",
1616
"basePath": "{{.BasePath}}",
1717
"paths": {
18+
"/api/v1/accounts": {
19+
"get": {
20+
"description": "List accounts",
21+
"produces": [
22+
"application/json"
23+
],
24+
"tags": [
25+
"accounts"
26+
],
27+
"summary": "List accounts",
28+
"responses": {
29+
"200": {
30+
"description": "OK",
31+
"schema": {
32+
"type": "array",
33+
"items": {
34+
"$ref": "#/definitions/model.AccountDTO"
35+
}
36+
}
37+
},
38+
"500": {
39+
"description": "Internal Server Error",
40+
"schema": {
41+
"type": "string"
42+
}
43+
}
44+
}
45+
},
46+
"post": {
47+
"produces": [
48+
"application/json"
49+
],
50+
"tags": [
51+
"accounts"
52+
],
53+
"summary": "Create an account",
54+
"responses": {
55+
"201": {
56+
"description": "Created",
57+
"schema": {
58+
"type": "array",
59+
"items": {
60+
"$ref": "#/definitions/model.AccountDTO"
61+
}
62+
}
63+
},
64+
"400": {
65+
"description": "Bad Request",
66+
"schema": {
67+
"type": "string"
68+
}
69+
},
70+
"500": {
71+
"description": "Internal Server Error",
72+
"schema": {
73+
"type": "string"
74+
}
75+
}
76+
}
77+
}
78+
},
79+
"/api/v1/accounts/{id}": {
80+
"delete": {
81+
"produces": [
82+
"application/json"
83+
],
84+
"tags": [
85+
"accounts"
86+
],
87+
"summary": "Delete an account",
88+
"responses": {
89+
"204": {
90+
"description": "No content",
91+
"schema": {
92+
"type": "string"
93+
}
94+
},
95+
"500": {
96+
"description": "Internal Server Error",
97+
"schema": {
98+
"type": "string"
99+
}
100+
}
101+
}
102+
},
103+
"patch": {
104+
"produces": [
105+
"application/json"
106+
],
107+
"tags": [
108+
"accounts"
109+
],
110+
"summary": "Update an account",
111+
"responses": {
112+
"200": {
113+
"description": "OK",
114+
"schema": {
115+
"type": "array",
116+
"items": {
117+
"$ref": "#/definitions/api_v1.updateAccountPayload"
118+
}
119+
}
120+
},
121+
"400": {
122+
"description": "Bad Request",
123+
"schema": {
124+
"type": "string"
125+
}
126+
},
127+
"500": {
128+
"description": "Internal Server Error",
129+
"schema": {
130+
"type": "string"
131+
}
132+
}
133+
}
134+
}
135+
},
18136
"/api/v1/auth/account": {
19137
"patch": {
20138
"produces": [
@@ -23,14 +141,14 @@ const docTemplate = `{
23141
"tags": [
24142
"Auth"
25143
],
26-
"summary": "Perform actions on the currently logged-in user.",
144+
"summary": "Update account information",
27145
"parameters": [
28146
{
29-
"description": "Config data",
147+
"description": "Account data",
30148
"name": "payload",
31149
"in": "body",
32150
"schema": {
33-
"$ref": "#/definitions/api_v1.settingRequestPayload"
151+
"$ref": "#/definitions/api_v1.updateAccountPayload"
34152
}
35153
}
36154
],
@@ -82,6 +200,25 @@ const docTemplate = `{
82200
}
83201
}
84202
},
203+
"/api/v1/auth/logout": {
204+
"post": {
205+
"produces": [
206+
"application/json"
207+
],
208+
"tags": [
209+
"Auth"
210+
],
211+
"summary": "Logout from the current session",
212+
"responses": {
213+
"200": {
214+
"description": "Logout successful"
215+
},
216+
"403": {
217+
"description": "Token not provided/invalid"
218+
}
219+
}
220+
}
221+
},
85222
"/api/v1/auth/me": {
86223
"get": {
87224
"produces": [
@@ -321,11 +458,23 @@ const docTemplate = `{
321458
}
322459
}
323460
},
324-
"api_v1.settingRequestPayload": {
461+
"api_v1.updateAccountPayload": {
325462
"type": "object",
326463
"properties": {
327464
"config": {
328465
"$ref": "#/definitions/model.UserConfig"
466+
},
467+
"new_password": {
468+
"type": "string"
469+
},
470+
"old_password": {
471+
"type": "string"
472+
},
473+
"owner": {
474+
"type": "boolean"
475+
},
476+
"username": {
477+
"type": "string"
329478
}
330479
}
331480
},
@@ -375,6 +524,27 @@ const docTemplate = `{
375524
}
376525
}
377526
},
527+
"model.AccountDTO": {
528+
"type": "object",
529+
"properties": {
530+
"config": {
531+
"$ref": "#/definitions/model.UserConfig"
532+
},
533+
"id": {
534+
"type": "integer"
535+
},
536+
"owner": {
537+
"type": "boolean"
538+
},
539+
"passowrd": {
540+
"description": "Used only to store, not to retrieve",
541+
"type": "string"
542+
},
543+
"username": {
544+
"type": "string"
545+
}
546+
}
547+
},
378548
"model.BookmarkDTO": {
379549
"type": "object",
380550
"properties": {

0 commit comments

Comments
 (0)