Skip to content

Commit f72b6b8

Browse files
committed
comments + refactor
1 parent c46299f commit f72b6b8

49 files changed

Lines changed: 927 additions & 687 deletions

Some content is hidden

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

.github/workflows/go.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535

3636
build-and-release:
3737
name: Build and Release
38-
needs: tests # only release if security AND all tests pass
38+
needs: tests # only release if all tests pass
3939
if: startsWith(github.ref, 'refs/tags/') # only with tag push (vX.X.X)
4040
runs-on: ubuntu-latest
4141
permissions:
@@ -55,7 +55,9 @@ jobs:
5555
- name: Release
5656
uses: softprops/action-gh-release@v3
5757
with:
58-
files: build/web/core.wasm
58+
files: |
59+
build/web/core.wasm
60+
build/web/wasm_exec.js
5961
generate_release_notes: true
6062
env:
6163
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

cmd/wasm/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import (
1313
func main() {
1414
api := api.NewApi()
1515

16-
RegisterCallbacks(api)
16+
registerCallbacks(api)
1717

1818
select {} // block infinitely
1919
}
2020

21-
func RegisterCallbacks(api *api.Api) {
21+
func registerCallbacks(api *api.Api) {
2222
js.Global().Set(
2323
"CalendarCore",
2424
js.ValueOf(map[string]any{ // we wrap each method

e2e/calendars_test.go

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,25 @@ import (
66
"os"
77
"path/filepath"
88
"testing"
9+
"time"
910

1011
"github.com/git-calendar/core/pkg/core"
1112
"github.com/git-calendar/core/pkg/filesystem"
13+
"github.com/google/uuid"
1214
)
1315

14-
const TestCalendarName = "test"
16+
const testCalendarName = "test"
1517

1618
func TestCreateCalendar(t *testing.T) {
1719
c := core.NewCore()
1820

19-
err := c.CreateCalendar(TestCalendarName, "")
21+
err := c.CreateCalendar(testCalendarName, "")
2022
if err != nil {
2123
t.Fatalf("failed to init repo: %v", err)
2224
}
2325

2426
t.Cleanup(func() {
25-
_ = c.RemoveCalendar(TestCalendarName)
27+
_ = c.RemoveCalendar(testCalendarName)
2628
})
2729

2830
home, err := os.UserHomeDir()
@@ -37,7 +39,7 @@ func TestCreateCalendar(t *testing.T) {
3739

3840
var found bool
3941
for _, d := range dirs {
40-
if d.Name() == TestCalendarName {
42+
if d.Name() == testCalendarName {
4143
found = true
4244
break
4345
}
@@ -50,13 +52,13 @@ func TestCreateCalendar(t *testing.T) {
5052
func TestListCalendars(t *testing.T) {
5153
c := core.NewCore()
5254

53-
err := c.CreateCalendar(TestCalendarName, "")
55+
err := c.CreateCalendar(testCalendarName, "")
5456
if err != nil {
5557
t.Fatalf("failed to create calendar: %v", err)
5658
}
5759

5860
t.Cleanup(func() {
59-
_ = c.RemoveCalendar(TestCalendarName)
61+
_ = c.RemoveCalendar(testCalendarName)
6062
})
6163

6264
calendars, err := c.ListCalendars()
@@ -66,7 +68,7 @@ func TestListCalendars(t *testing.T) {
6668

6769
var found bool
6870
for _, calendar := range calendars {
69-
if calendar.Name != TestCalendarName {
71+
if calendar.Name != testCalendarName {
7072
continue
7173
}
7274

@@ -82,25 +84,25 @@ func TestListCalendars(t *testing.T) {
8284
}
8385

8486
if !found {
85-
t.Errorf("calendar %q not found in list", TestCalendarName)
87+
t.Errorf("calendar %q not found in list", testCalendarName)
8688
}
8789
}
8890

8991
func TestListCalendars_WithRemote(t *testing.T) {
9092
c := core.NewCore()
9193

92-
err := c.CreateCalendar(TestCalendarName, "")
94+
err := c.CreateCalendar(testCalendarName, "")
9395
if err != nil {
9496
t.Fatalf("failed to create calendar: %v", err)
9597
}
9698

9799
t.Cleanup(func() {
98-
_ = c.RemoveCalendar(TestCalendarName)
100+
_ = c.RemoveCalendar(testCalendarName)
99101
})
100102

101103
remoteUrl := "https://github.com/git-calendar/calendar.git"
102104

103-
err = c.UpdateRemote(TestCalendarName, mustParseUrl(remoteUrl), false)
105+
err = c.UpdateRemote(testCalendarName, mustParseUrl(remoteUrl), false)
104106
if err != nil {
105107
t.Fatalf("failed to update remotes: %v", err)
106108
}
@@ -112,7 +114,7 @@ func TestListCalendars_WithRemote(t *testing.T) {
112114

113115
var found bool
114116
for _, calendar := range calendars {
115-
if calendar.Name != TestCalendarName {
117+
if calendar.Name != testCalendarName {
116118
continue
117119
}
118120
rurl, err := calendar.RemoteURL()
@@ -127,19 +129,22 @@ func TestListCalendars_WithRemote(t *testing.T) {
127129
}
128130

129131
if !found {
130-
t.Errorf("calendar %q not found in list", TestCalendarName)
132+
t.Errorf("calendar %q not found in list", testCalendarName)
131133
}
132134
}
133135

134136
func TestRemoveCalendar(t *testing.T) {
135137
c := core.NewCore()
136138

137-
err := c.CreateCalendar(TestCalendarName, "")
139+
err := c.CreateCalendar(testCalendarName, "")
138140
if err != nil {
139141
t.Fatalf("failed to create calendar: %v", err)
140142
}
143+
if err := c.UpdateRemote(testCalendarName, mustParseUrl("https://example.com/calendar.git"), true); err != nil {
144+
t.Fatalf("failed to make calendar read-only: %v", err)
145+
}
141146

142-
err = c.RemoveCalendar(TestCalendarName)
147+
err = c.RemoveCalendar(testCalendarName)
143148
if err != nil {
144149
t.Fatalf("failed to remove calendar: %v", err)
145150
}
@@ -149,7 +154,7 @@ func TestRemoveCalendar(t *testing.T) {
149154
t.Errorf("failed to get home dir: %v", err)
150155
}
151156

152-
calendarPath := filepath.Join(home, filesystem.DirName, TestCalendarName)
157+
calendarPath := filepath.Join(home, filesystem.DirName, testCalendarName)
153158

154159
_, err = os.Stat(calendarPath)
155160
if err == nil {
@@ -159,13 +164,18 @@ func TestRemoveCalendar(t *testing.T) {
159164
if err != nil && !os.IsNotExist(err) {
160165
t.Errorf("failed to check calendar directory: %v", err)
161166
}
167+
168+
readonlyPath := filepath.Join(home, filesystem.DirName, testCalendarName+core.ReadonlyFileSuffix)
169+
if _, err := os.Stat(readonlyPath); !os.IsNotExist(err) {
170+
t.Errorf("read-only marker still exists or could not be checked: %v", err)
171+
}
162172
}
163173

164174
func TestRenameCalendar(t *testing.T) {
165175
c := core.NewCore()
166176

167-
oldName := TestCalendarName + "_old"
168-
newName := TestCalendarName + "_new"
177+
oldName := testCalendarName + "_old"
178+
newName := testCalendarName + "_new"
169179

170180
err := c.CreateCalendar(oldName, "")
171181
if err != nil {
@@ -176,6 +186,18 @@ func TestRenameCalendar(t *testing.T) {
176186
_ = c.RemoveCalendar(oldName)
177187
})
178188

189+
start := time.Date(2026, 1, 1, 9, 0, 0, 0, time.UTC)
190+
event, err := c.CreateEvent(core.Event{
191+
ID: uuid.New(),
192+
Title: "Renamed calendar event",
193+
From: start,
194+
To: start.Add(time.Hour),
195+
Calendar: oldName,
196+
})
197+
if err != nil {
198+
t.Fatalf("failed to create event: %v", err)
199+
}
200+
179201
err = c.RenameCalendar(oldName, newName)
180202
if err != nil {
181203
t.Fatalf("failed to rename calendar: %v", err)
@@ -185,6 +207,14 @@ func TestRenameCalendar(t *testing.T) {
185207
_ = c.RemoveCalendar(newName)
186208
})
187209

210+
renamedEvent, err := c.GetEvent(event.ID)
211+
if err != nil {
212+
t.Fatalf("failed to get event after rename: %v", err)
213+
}
214+
if renamedEvent.Calendar != newName {
215+
t.Fatalf("event calendar = %q, want %q", renamedEvent.Calendar, newName)
216+
}
217+
188218
home, err := os.UserHomeDir()
189219
if err != nil {
190220
t.Errorf("failed to get home dir: %v", err)
@@ -211,15 +241,15 @@ func TestRenameCalendar(t *testing.T) {
211241
func TestRenameCalendar_SameName(t *testing.T) {
212242
c := core.NewCore()
213243

214-
err := c.CreateCalendar(TestCalendarName, "")
244+
err := c.CreateCalendar(testCalendarName, "")
215245
if err != nil {
216246
t.Fatalf("failed to create calendar: %v", err)
217247
}
218248
t.Cleanup(func() {
219-
_ = c.RemoveCalendar(TestCalendarName)
249+
_ = c.RemoveCalendar(testCalendarName)
220250
})
221251

222-
err = c.RenameCalendar(TestCalendarName, TestCalendarName)
252+
err = c.RenameCalendar(testCalendarName, testCalendarName)
223253
if err != nil {
224254
t.Fatalf("renaming calendar to same name should not fail: %v", err)
225255
}
@@ -229,7 +259,7 @@ func TestRenameCalendar_SameName(t *testing.T) {
229259
t.Errorf("failed to get home dir: %v", err)
230260
}
231261

232-
calendarPath := filepath.Join(home, filesystem.DirName, TestCalendarName)
262+
calendarPath := filepath.Join(home, filesystem.DirName, testCalendarName)
233263

234264
_, err = os.Stat(calendarPath)
235265
if err != nil {
@@ -240,9 +270,9 @@ func TestRenameCalendar_SameName(t *testing.T) {
240270
func TestRenameCalendar_MissingCalendar(t *testing.T) {
241271
c := core.NewCore()
242272

243-
c.RemoveCalendar(TestCalendarName)
273+
c.RemoveCalendar(testCalendarName)
244274

245-
err := c.RenameCalendar(TestCalendarName, "new-calendar")
275+
err := c.RenameCalendar(testCalendarName, "new-calendar")
246276
if err == nil {
247277
t.Fatal("expected error when renaming missing calendar")
248278
}
@@ -251,8 +281,8 @@ func TestRenameCalendar_MissingCalendar(t *testing.T) {
251281
func TestRenameCalendar_AlreadyExists(t *testing.T) {
252282
c := core.NewCore()
253283

254-
oldName := TestCalendarName + "_old"
255-
newName := TestCalendarName + "_new"
284+
oldName := testCalendarName + "_old"
285+
newName := testCalendarName + "_new"
256286

257287
err := c.CreateCalendar(oldName, "")
258288
if err != nil {

e2e/encryption_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ import (
1717
func TestCreateCalendarWithPassword_CreatesKeyFile(t *testing.T) {
1818
c := core.NewCore()
1919

20-
err := c.CreateCalendar(TestCalendarName, "somepassword")
20+
err := c.CreateCalendar(testCalendarName, "somepassword")
2121
if err != nil {
2222
t.Fatalf("failed to init repo: %v", err)
2323
}
2424

2525
t.Cleanup(func() {
26-
_ = c.RemoveCalendar(TestCalendarName)
26+
_ = c.RemoveCalendar(testCalendarName)
2727
})
2828

2929
home, err := os.UserHomeDir()
3030
if err != nil {
3131
t.Errorf("failed to get home dir: %v", err)
3232
}
3333

34-
b, err := os.ReadFile(filepath.Join(home, filesystem.DirName, TestCalendarName+core.KeyFileSuffix))
34+
b, err := os.ReadFile(filepath.Join(home, filesystem.DirName, testCalendarName+core.KeyFileSuffix))
3535
if err != nil {
3636
t.Errorf("failed to read key file: %v", err)
3737
}
@@ -44,20 +44,20 @@ func TestCreateCalendarWithPassword_CreatesKeyFile(t *testing.T) {
4444
func TestCreateCalendarWithPasswordAndCreateEvent_CreatesJsonFile(t *testing.T) {
4545
c := core.NewCore()
4646

47-
err := c.CreateCalendar(TestCalendarName, "somepassword")
47+
err := c.CreateCalendar(testCalendarName, "somepassword")
4848
if err != nil {
4949
t.Fatalf("failed to init repo: %v", err)
5050
}
5151

5252
t.Cleanup(func() {
53-
_ = c.RemoveCalendar(TestCalendarName)
53+
_ = c.RemoveCalendar(testCalendarName)
5454
})
5555

5656
id := uuid.New()
5757
title := "Foo Event"
5858
eventIn := core.Event{
59-
Id: id,
60-
Calendar: TestCalendarName,
59+
ID: id,
60+
Calendar: testCalendarName,
6161
Title: title,
6262
From: time.Now(),
6363
To: time.Now().Add(2 * time.Hour),
@@ -73,7 +73,7 @@ func TestCreateCalendarWithPasswordAndCreateEvent_CreatesJsonFile(t *testing.T)
7373
t.Errorf("failed to get home dir: %v", err)
7474
}
7575

76-
b, err := os.ReadFile(filepath.Join(home, filesystem.DirName, TestCalendarName, core.EventsDirName, fmt.Sprintf("%s.json", id)))
76+
b, err := os.ReadFile(filepath.Join(home, filesystem.DirName, testCalendarName, core.EventsDirName, fmt.Sprintf("%s.json", id)))
7777
if err != nil {
7878
t.Errorf("failed to read event json file: %v", err)
7979
}

0 commit comments

Comments
 (0)