Skip to content
This repository was archived by the owner on Aug 25, 2023. It is now read-only.

Commit ceed0ae

Browse files
sviandeahmdrz
authored andcommitted
Feedtag test (#265) [skip ci]
* FeedTag & Hashtag: update decoding flow * FeedTag: add tests * Contributing: add process for launching tests
1 parent 380c942 commit ceed0ae

File tree

4 files changed

+63
-6
lines changed

4 files changed

+63
-6
lines changed

CONTRIBUTING.md

+27
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,30 @@ If you want to contribute to Goinsta API you must follow a simple instructions.
66

77
- **Test your code after making pull request**. The title says it all.
88
- **Include jokes if you can**. This instruction is optional.
9+
10+
# Tests
11+
12+
You need at least one goinsta exported object
13+
```
14+
package main
15+
16+
import (
17+
"fmt"
18+
"github.com/ahmdrz/goinsta/v2"
19+
"github.com/ahmdrz/goinsta/v2/utilities"
20+
)
21+
22+
func main() {
23+
inst := goinsta.New("user", "password")
24+
err := inst.Login()
25+
if err != nil {
26+
fmt.Fatal(err)
27+
}
28+
fmt.Print(utilities.ExportAsBase64String(inst))
29+
}
30+
```
31+
32+
Then you can use the output generated above to run your tests in the cli
33+
```
34+
INSTAGRAM_BASE64_USERNAME=BASE64_OUTPUT go test ./...
35+
```

feeds.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ func (ft *FeedTag) Next() bool {
131131
},
132132
)
133133
if err == nil {
134-
newFT := FeedTag{}
135-
err = json.Unmarshal(body, &newFT)
134+
newFT := &FeedTag{}
135+
err = json.Unmarshal(body, newFT)
136136
if err == nil {
137-
*ft = newFT
137+
*ft = *newFT
138138
ft.inst = insta
139139
ft.name = name
140140
if !ft.MoreAvailable {

hashtags.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ func (h *Hashtag) Next() bool {
101101
},
102102
)
103103
if err == nil {
104-
ht := Hashtag{}
105-
err = json.Unmarshal(body, &ht)
104+
ht := &Hashtag{}
105+
err = json.Unmarshal(body, ht)
106106
if err == nil {
107-
*h = ht
107+
*h = *ht
108108
h.inst = insta
109109
h.Name = name
110110
if !h.MoreAvailable {

tests/feed_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,33 @@ func TestFeedTagLike(t *testing.T) {
2929
t.Logf("media %s liked by goinsta", item.ID)
3030
}
3131
}
32+
33+
func TestFeedTagNext(t *testing.T) {
34+
insta, err := getRandomAccount()
35+
if err != nil {
36+
t.Fatal(err)
37+
return
38+
}
39+
feedTag, err := insta.Feed.Tags("golang")
40+
if err != nil {
41+
t.Fatal(err)
42+
return
43+
}
44+
45+
initNextID := feedTag.NextID
46+
success := feedTag.Next()
47+
if !success {
48+
t.Fatal("Failed to fetch next page")
49+
return
50+
}
51+
gotStatus := feedTag.Status
52+
53+
if gotStatus != "ok" {
54+
t.Errorf("Status = %s; want ok", gotStatus)
55+
}
56+
57+
gotNextID := feedTag.NextID
58+
if gotNextID == initNextID {
59+
t.Errorf("NextID must differ after FeedTag.Next() call")
60+
}
61+
}

0 commit comments

Comments
 (0)