Browse Source

closes T589 update tests to use dev client

this changes tests to only use the dev client as all code is shared
between that and the write.as client, just the host changes.

also updated post tests to round trip and test over sub tests
v2
Rob Loranger 1 year ago
parent
commit
de8ce4dcd2
No known key found for this signature in database GPG Key ID: D6F1633A4F0903B8
2 changed files with 83 additions and 102 deletions
  1. +27
    -29
      collection_test.go
  2. +56
    -73
      post_test.go

+ 27
- 29
collection_test.go View File

@@ -8,47 +8,45 @@ import (
)

func TestGetCollection(t *testing.T) {
wac := NewClient()
dwac := NewDevClient()

res, err := wac.GetCollection("blog")
res, err := dwac.GetCollection("tester")
if err != nil {
t.Errorf("Unexpected fetch results: %+v, err: %v\n", res, err)
} else {
t.Logf("Collection: %+v", res)
if res.Title != "write.as blog" {
t.Errorf("Unexpected fetch results: %+v\n", res)
}
}
if res == nil {
t.Error("Expected collection to not be nil")
}
}

func TestGetCollectionPosts(t *testing.T) {
wac := NewClient()
dwac := NewDevClient()
posts := []Post{}

res, err := wac.GetCollectionPosts("blog")
if err != nil {
t.Errorf("Unexpected fetch results: %+v, err: %v\n", res, err)
} else {
t.Run("Get all posts in collection", func(t *testing.T) {
res, err := dwac.GetCollectionPosts("tester")
if err != nil {
t.Errorf("Unexpected fetch results: %+v, err: %v\n", res, err)
}
if len(*res) == 0 {
t.Errorf("No posts returned!")
t.Error("Expected at least on post in collection")
}
posts = *res
})
t.Run("Get one post from collection", func(t *testing.T) {
res, err := dwac.GetCollectionPost("tester", posts[0].Slug)
if err != nil {
t.Errorf("Unexpected fetch results: %+v, err: %v\n", res, err)
}
}
}

func TestGetCollectionPost(t *testing.T) {
wac := NewClient()

res, err := wac.GetCollectionPost("blog", "extending-write-as")
if err != nil {
t.Errorf("Unexpected fetch results: %+v, err: %v\n", res, err)
}

if res == nil {
t.Errorf("No post returned!")
}
if res == nil {
t.Errorf("No post returned!")
}

if len(res.Content) == 0 {
t.Errorf("Post content is empty!")
}
if len(res.Content) == 0 {
t.Errorf("Post content is empty!")
}
})
}

func TestGetUserCollections(t *testing.T) {


+ 56
- 73
post_test.go View File

@@ -2,82 +2,57 @@ package writeas

import (
"fmt"
"strings"
"testing"
)

func TestCreatePost(t *testing.T) {
wac := NewClient()
p, err := wac.CreatePost(&PostParams{
Title: "Title!",
Content: "This is a post.",
Font: "sans",
func TestPostRoundTrip(t *testing.T) {
var id, token string
dwac := NewClient()
t.Run("Create post", func(t *testing.T) {
p, err := dwac.CreatePost(&PostParams{
Title: "Title!",
Content: "This is a post.",
Font: "sans",
})
if err != nil {
t.Errorf("Post create failed: %v", err)
return
}
t.Logf("Post created: %+v", p)
id, token = p.ID, p.Token
})
if err != nil {
t.Errorf("Post create failed: %v", err)
return
}
t.Logf("Post created: %+v", p)

token := p.Token

// Update post
p, err = wac.UpdatePost(p.ID, token, &PostParams{
Content: "Now it's been updated!",
t.Run("Get post", func(t *testing.T) {
res, err := dwac.GetPost(id)
if err != nil {
t.Errorf("Unexpected fetch results: %+v, err: %v\n", res, err)
} else {
t.Logf("Post: %+v", res)
if res.Content != "This is a post." {
t.Errorf("Unexpected fetch results: %+v\n", res)
}
}
})
if err != nil {
t.Errorf("Post update failed: %v", err)
return
}
t.Logf("Post updated: %+v", p)

// Delete post
err = wac.DeletePost(p.ID, token)
if err != nil {
t.Errorf("Post delete failed: %v", err)
return
}
t.Logf("Post deleted!")
}

func TestGetPost(t *testing.T) {
dwac := NewDevClient()
res, err := dwac.GetPost("zekk5r9apum6p")
if err != nil {
t.Errorf("Unexpected fetch results: %+v, err: %v\n", res, err)
} else {
t.Logf("Post: %+v", res)
if res.Content != "This is a post." {
t.Errorf("Unexpected fetch results: %+v\n", res)
t.Run("Update post", func(t *testing.T) {
p, err := dwac.UpdatePost(id, token, &PostParams{
Content: "Now it's been updated!",
})
if err != nil {
t.Errorf("Post update failed: %v", err)
return
}
}

wac := NewClient()
res, err = wac.GetPost("3psnxyhqxy3hq")
if err != nil {
t.Errorf("Unexpected fetch results: %+v, err: %v\n", res, err)
} else {
if !strings.HasPrefix(res.Content, " Write.as Blog") {
t.Errorf("Unexpected fetch results: %+v\n", res)
t.Logf("Post updated: %+v", p)
})
t.Run("Delete post", func(t *testing.T) {
err := dwac.DeletePost(id, token)
if err != nil {
t.Errorf("Post delete failed: %v", err)
return
}
}
}

func TestPinPost(t *testing.T) {
dwac := NewDevClient()
_, err := dwac.LogIn("demo", "demo")
if err != nil {
t.Fatalf("Unable to log in: %v", err)
}
defer dwac.LogOut()

err = dwac.PinPost("tester", &PinnedPostParams{ID: "olx6uk7064heqltf"})
if err != nil {
t.Fatalf("Pin failed: %v", err)
}
t.Logf("Post deleted!")
})
}

func TestUnpinPost(t *testing.T) {
func TestPinUnPin(t *testing.T) {
dwac := NewDevClient()
_, err := dwac.LogIn("demo", "demo")
if err != nil {
@@ -85,17 +60,25 @@ func TestUnpinPost(t *testing.T) {
}
defer dwac.LogOut()

err = dwac.UnpinPost("tester", &PinnedPostParams{ID: "olx6uk7064heqltf"})
if err != nil {
t.Fatalf("Unpin failed: %v", err)
}
t.Run("Pin post", func(t *testing.T) {
err := dwac.PinPost("tester", &PinnedPostParams{ID: "olx6uk7064heqltf"})
if err != nil {
t.Fatalf("Pin failed: %v", err)
}
})
t.Run("Unpin post", func(t *testing.T) {
err := dwac.UnpinPost("tester", &PinnedPostParams{ID: "olx6uk7064heqltf"})
if err != nil {
t.Fatalf("Unpin failed: %v", err)
}
})
}

func ExampleClient_CreatePost() {
c := NewClient()
dwac := NewDevClient()

// Publish a post
p, err := c.CreatePost(&PostParams{
p, err := dwac.CreatePost(&PostParams{
Title: "Title!",
Content: "This is a post.",
Font: "sans",


Loading…
Cancel
Save