This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 269
/
regressions.js
118 lines (87 loc) · 3.96 KB
/
regressions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
module.exports = scenario => {
scenario('calling get_links before link_entries makes no difference', async (s, t, {alice}) => {
const get1 = await alice.call("blog", "my_posts", {})
t.ok(get1.Ok)
const create1 = await alice.callSync("blog","create_post", {content: 'hi'})
t.ok(create1.Ok)
const get2 = await alice.call("blog", "my_posts", {})
t.ok(get2.Ok)
t.equal(get2.Ok.links.length, 1)
})
scenario('calling get_links twice in a row is no different than calling it once', async (s, t, {alice}) => {
// This test is exactly the same as the previous one, but calls my_posts twice in a row.
// This makes the links come through the second time.
const get1 = await alice.call("blog", "my_posts", {})
t.ok(get1.Ok)
const create1 = await alice.callSync("blog", "create_post", {content: 'hi'})
t.ok(create1.Ok)
await alice.call("blog", "my_posts", {})
const get2 = await alice.call("blog", "my_posts", {})
t.ok(get2.Ok)
t.equal(get2.Ok.links.length, 1)
})
scenario('not calling get_links in the beginning is also ok', async (s, t, {alice}) => {
const create1 = await alice.callSync("blog", "create_post", {content: 'hi'})
t.ok(create1.Ok)
const get1 = await alice.call("blog", "my_posts", {})
t.ok(get1.Ok)
t.equal(get1.Ok.links.length, 1)
})
scenario('alice create & publish post -> recommend own post to self', async (s, t, {alice, bob}) => {
const content = "Holo world...1"
const params = { content: content, in_reply_to: null }
const postResult = await alice.callSync("blog", "create_post", params)
const postAddr = postResult.Ok
t.ok(postAddr, `error: ${postResult}`)
const gotPost = await alice.call("blog", "get_post", {post_address: postAddr})
t.ok(gotPost.Ok)
let linked = await alice.callSync('blog', 'recommend_post', {
post_address: postAddr,
agent_address: alice.agentId
})
console.log("linked: ", linked)
t.equal(linked.Ok, "QmZr5F34uGZjAEwmU574VwiRtXGHQmvbUnNgA2MJz7YcTr")
const recommendedPosts = await alice.call('blog', 'my_recommended_posts', {})
console.log("recommendedPosts", recommendedPosts)
console.log('agent addresses: ', alice.agentId, alice.agentId)
t.equal(recommendedPosts.Ok.links.length, 1)
})
scenario('alice create & publish post -> bob recommend to self', async (s, t, {alice, bob}) => {
const content = "Holo world...2"
const params = { content: content, in_reply_to: null }
const postResult = await alice.callSync("blog", "create_post", params)
const postAddr = postResult.Ok
t.ok(postAddr, `error: ${postResult}`)
const gotPost = await bob.call("blog", "get_post", {post_address: postAddr})
t.ok(gotPost.Ok)
let linked = await bob.callSync('blog', 'recommend_post', {
post_address: postAddr,
agent_address: bob.agentId
})
console.log("linked: ", linked)
t.equal(linked.Ok, "QmT2Z8Hdkgxkt7X4ZeEkoDt3YTQBzyJa1RNPhfkj9icsQ4")
const recommendedPosts = await bob.call("blog", "my_recommended_posts", {})
console.log("recommendedPosts", recommendedPosts)
console.log('agent addresses: ', alice.agentId, bob.agentId)
t.equal(recommendedPosts.Ok.links.length, 1)
})
scenario('create & publish post -> recommend to other agent', async (s, t, {alice, bob}) => {
const content = "Holo world...3"
const params = { content: content, in_reply_to: null }
const postResult = await alice.callSync("blog", "create_post", params)
const postAddr = postResult.Ok
t.ok(postAddr, `error: ${postResult}`)
const gotPost = await bob.call("blog", "get_post", {post_address: postAddr})
t.ok(gotPost.Ok)
let linked = await alice.callSync('blog', 'recommend_post', {
post_address: postAddr,
agent_address: bob.agentId
})
console.log("linked: ", linked)
t.equal(linked.Ok, "QmUFkn3kTXuFmBvynEMQ4ox3WyvkkG4GtfvPkNqb5b7Ge7")
const recommendedPosts = await bob.call('blog', 'my_recommended_posts', {})
console.log("recommendedPosts", recommendedPosts)
console.log('agent addresses: ', alice.agentId, bob.agentId)
t.equal(recommendedPosts.Ok.links.length, 1)
})
}