From 0b15a3b786bce10c112655fddbb4cc5b74e7a0d3 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 12 Sep 2024 10:33:11 +0300 Subject: refactor a bit --- internal/server/repository/pending_test.go | 14 +++++++++----- internal/server/repository/repository_test.go | 12 ++++++------ internal/types/entry.go | 1 - internal/types/entry_test.go | 18 +++++++++--------- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/internal/server/repository/pending_test.go b/internal/server/repository/pending_test.go index 9f9ca84..f149856 100644 --- a/internal/server/repository/pending_test.go +++ b/internal/server/repository/pending_test.go @@ -1,11 +1,15 @@ package repository -import "testing" +import ( + "testing" + + "codeberg.org/snonux/gos/internal/types" +) func TestPendingAdd(t *testing.T) { pending := newPending() - entries, ok := pending.get("LinkedIn") + entries, ok := pending.get(types.LinkedIn) if ok { t.Error("expected no ok return status") } @@ -15,10 +19,10 @@ func TestPendingAdd(t *testing.T) { // TODO REFACTOR: Use constants for types.PlatformName's // TODO REFACTOR: Don't use a type alias for types.PlatformName anymore, but an own type. - pending.add("LinkedIn", "foo") - pending.add("LinkedIn", "bar") + pending.add(types.LinkedIn, "foo") + pending.add(types.LinkedIn, "bar") - entries, ok = pending.get("LinkedIn") + entries, ok = pending.get(types.LinkedIn) if !ok { t.Error("expected ok return status") } diff --git a/internal/server/repository/repository_test.go b/internal/server/repository/repository_test.go index 20fa6ec..37ca8dc 100644 --- a/internal/server/repository/repository_test.go +++ b/internal/server/repository/repository_test.go @@ -251,17 +251,17 @@ func TestRepositoryMergeFromPartner(t *testing.T) { } // Validate the correct test setup - if entry.IsShared("LinkedIn") { + if entry.IsShared(types.LinkedIn) { t.Error("for the test expected LinkedIn not to be shared") } // Simulate that the entry was shared to LinkedIn social media! - linkedIn, ok := entry.Shared["LinkedIn"] + linkedIn, ok := entry.Shared[types.LinkedIn] if !ok { t.Error("expected to have a LinkedIn shared entry") } linkedIn.Is = true - entry.Shared["LinkedIn"] = linkedIn + entry.Shared[types.LinkedIn] = linkedIn if err := repo1.Update(entry); err != nil { t.Error(err) @@ -305,11 +305,11 @@ func TestRepositoryNext(t *testing.T) { _ = repo.put(entry) } - if entry, ok := repo.Next("Mastodon"); ok { + if entry, ok := repo.Next(types.Mastodon); ok { t.Error("expected no Mastodon entry to be found", entry) } - if _, ok := repo.Next("LinkedIn"); !ok { + if _, ok := repo.Next(types.LinkedIn); !ok { t.Error("expected an unshared LinkedIn entry to be found") } @@ -350,7 +350,7 @@ func makeAnotherEntry() (types.Entry, error) { "shared": { "Mastodon": { "is": true }, "LinkedIn": { "is": true }, - "foo.zone": { "is": false } + "Textfile": { "is": false } } } ` diff --git a/internal/types/entry.go b/internal/types/entry.go index 9f3531a..f17c06a 100644 --- a/internal/types/entry.go +++ b/internal/types/entry.go @@ -10,7 +10,6 @@ import ( "strings" ) -type PlatformName = string type EntryID = string type Epoch = int diff --git a/internal/types/entry_test.go b/internal/types/entry_test.go index 3dde570..40f0955 100644 --- a/internal/types/entry_test.go +++ b/internal/types/entry_test.go @@ -15,11 +15,11 @@ func TestNewEntryFromJSON(t *testing.T) { if len(entry1.Shared) != 2 { t.Error("expected to have two shared entries in entry1") } - if !entry1.IsShared("Foo") { - t.Error("Foo should be shared") + if !entry1.IsShared("Mastodon") { + t.Error("Mastodon should be shared") } - if entry1.IsShared("Bar") { - t.Error("Bar should not be shared") + if entry1.IsShared("LinkedIn") { + t.Error("LinkedIn should not be shared") } } @@ -114,8 +114,8 @@ func oneEntry() (Entry, error) { { "body": "Body text here", "shared": { - "Foo": { "is": true }, - "Bar": { "is": false } + "Mastodon": { "is": true }, + "LinkedIn": { "is": false } } } ` @@ -127,9 +127,9 @@ func anotherEntry() (Entry, error) { { "body": "Body text here", "shared": { - "Foo": { "is": true }, - "Bar": { "is": true }, - "Baz": { "is": false } + "Mastodon": { "is": true }, + "LinkedIn": { "is": true }, + "Textfile": { "is": false } } } ` -- cgit v1.2.3