Skip to content

Commit e2f4d8f

Browse files
committed
Completed API coverage for Pinata Cloud.
1 parent 021dba3 commit e2f4d8f

37 files changed

Lines changed: 775 additions & 305 deletions
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"count": 2,
3+
"rows": [
4+
{
5+
"id": "gggg",
6+
"ipfs_pin_hash": "QmR9HwzakHVr67HFzzgJHoRjwzTTt4wtD6KU4NFe2ArYuj",
7+
"size": 136,
8+
"user_id": "ffffff",
9+
"date_pinned": "2020-12-05T19:48:38.780Z",
10+
"date_unpinned": null,
11+
"metadata": {
12+
"name": "test3.html",
13+
"keyvalues": {
14+
"barbar": "jarjar"
15+
}
16+
},
17+
"regions": [
18+
{
19+
"regionId": "FRA1",
20+
"currentReplicationCount": 0,
21+
"desiredReplicationCount": 0
22+
},
23+
{
24+
"regionId": "NYC1",
25+
"currentReplicationCount": 1,
26+
"desiredReplicationCount": 1
27+
}
28+
]
29+
},
30+
{
31+
"id": "gggg",
32+
"ipfs_pin_hash": "Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye",
33+
"size": 7345778,
34+
"user_id": "fffff",
35+
"date_pinned": "2020-11-29T20:40:56.957Z",
36+
"date_unpinned": null,
37+
"metadata": {
38+
"name": "bogus_ipfs2",
39+
"keyvalues": null
40+
},
41+
"regions": [
42+
{
43+
"regionId": "FRA1",
44+
"currentReplicationCount": 1,
45+
"desiredReplicationCount": 1
46+
}
47+
]
48+
}
49+
]
50+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
count: 2,
3+
rows: [
4+
{
5+
id: gggg,
6+
ipfs_pin_hash: QmR9HwzakHVr67HFzzgJHoRjwzTTt4wtD6KU4NFe2ArYuj,
7+
size: 136,
8+
user_id: ffffff,
9+
date_pinned: DateTimeOffset_1,
10+
metadata: {
11+
name: test3.html,
12+
keyvalues: {
13+
barbar: jarjar
14+
}
15+
},
16+
regions: [
17+
{
18+
regionId: FRA1,
19+
currentReplicationCount: 0
20+
},
21+
{
22+
desiredReplicationCount: 1,
23+
regionId: NYC1,
24+
currentReplicationCount: 1
25+
}
26+
]
27+
},
28+
{
29+
id: gggg,
30+
ipfs_pin_hash: Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye,
31+
size: 7345778,
32+
user_id: fffff,
33+
date_pinned: DateTimeOffset_2,
34+
metadata: {
35+
name: bogus_ipfs2
36+
},
37+
regions: [
38+
{
39+
desiredReplicationCount: 1,
40+
regionId: FRA1,
41+
currentReplicationCount: 1
42+
}
43+
]
44+
}
45+
],
46+
IsSuccess: true
47+
}

Source/Pinata.Client.Tests/DataTests.UserPinnedDataTotal_with_no_values.server.json renamed to Source/Pinata.Client.Tests/EndpointTests/DataTests.UserPinnedDataTotal_with_no_values.server.json

File renamed without changes.

Source/Pinata.Client.Tests/DataTests.UserPinnedDataTotal_with_no_values.verified.json renamed to Source/Pinata.Client.Tests/EndpointTests/DataTests.UserPinnedDataTotal_with_no_values.verified.json

File renamed without changes.

Source/Pinata.Client.Tests/DataTests.UserPinnedDataTotal_with_values.server.json renamed to Source/Pinata.Client.Tests/EndpointTests/DataTests.UserPinnedDataTotal_with_values.server.json

File renamed without changes.

Source/Pinata.Client.Tests/DataTests.UserPinnedDataTotal_with_values.verified.json renamed to Source/Pinata.Client.Tests/EndpointTests/DataTests.UserPinnedDataTotal_with_values.verified.json

File renamed without changes.

Source/Pinata.Client.Tests/DataTests.cs renamed to Source/Pinata.Client.Tests/EndpointTests/DataTests.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using System.Net.Http;
21
using System.Threading.Tasks;
32
using NUnit.Framework;
3+
using static System.Net.Http.HttpMethod;
44

5-
namespace Pinata.Client.Tests
5+
namespace Pinata.Client.Tests.EndpointTests
66
{
77
public class DataTests : MockServerTest
88
{
@@ -29,7 +29,7 @@ public async Task UserPinnedDataTotal_with_no_values()
2929

3030
this.server
3131
.ShouldHaveCalledPath("/data/userPinnedDataTotal")
32-
.WithVerb(HttpMethod.Get);
32+
.WithVerb(Get);
3333

3434
await Verify(r);
3535
}
@@ -43,10 +43,28 @@ public async Task UserPinnedDataTotal_with_values()
4343

4444
this.server
4545
.ShouldHaveCalledPath("/data/userPinnedDataTotal")
46-
.WithVerb(HttpMethod.Get);
46+
.WithVerb(Get);
4747

4848
await Verify(r);
4949
}
5050

51+
[Test]
52+
public async Task Get_Pin_List()
53+
{
54+
this.server.RespondWithJsonTestFile();
55+
56+
var filter = new
57+
{
58+
status = "pinned"
59+
};
60+
61+
var r = await this.client.Data.PinList(filter);
62+
63+
this.server.ShouldHaveCalledPath("/data/pinList")
64+
.WithQueryParam("status", "pinned")
65+
.WithVerb(Get);
66+
67+
await Verify(r);
68+
}
5169
}
5270
}

Source/Pinata.Client.Tests/PinningTests.cs renamed to Source/Pinata.Client.Tests/EndpointTests/PinningTests.cs

Lines changed: 115 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
using System.Linq;
21
using System.Net.Http;
32
using System.Net.Mime;
43
using System.Text;
54
using System.Threading.Tasks;
65
using FluentAssertions;
7-
using Flurl.Http.Content;
86
using NUnit.Framework;
97
using static System.Net.Http.HttpMethod;
108

11-
namespace Pinata.Client.Tests
9+
namespace Pinata.Client.Tests.EndpointTests
1210
{
1311
public class PinningTests : MockServerTest
1412
{
@@ -66,7 +64,7 @@ public async Task pin_json_content_with_options()
6664

6765
var r = await this.client.Pinning.PinJsonToIpfsAsync(content, meta, opts);
6866

69-
var expectedBody = @"{""pinataContent"":{""hello"":""world""},""pinataOptions"":{""cidVersion"":1,""customPinPolicy"":{""regions"":[{""id"":""FRA1"",""desiredReplicationCount"":1}]},""wrapWithDirectory"":null},""pinataMetadata"":{""name"":""hello"",""keyvalues"":{""someKey"":""someValue""}}}";
67+
var expectedBody = @"{""pinataContent"":{""hello"":""world""},""pinataOptions"":{""cidVersion"":1,""customPinPolicy"":{""regions"":[{""id"":""FRA1"",""desiredReplicationCount"":1}]},""wrapWithDirectory"":null,""hostNodes"":null},""pinataMetadata"":{""name"":""hello"",""keyvalues"":{""someKey"":""someValue""}}}";
7068

7169
this.server.ShouldHaveCalledPath("/pinning/pinJSONToIPFS")
7270
.WithVerb(Post)
@@ -115,7 +113,8 @@ public async Task pin_json_object_with_options()
115113
};
116114
var r = await this.client.Pinning.PinJsonToIpfsAsync(body, meta, opts);
117115

118-
var expectedBody = @"{""pinataOptions"":{""cidVersion"":1,""customPinPolicy"":{""regions"":[{""id"":""FRA1"",""desiredReplicationCount"":1}]},""wrapWithDirectory"":null},""pinataMetadata"":{""name"":""hello"",""keyvalues"":{""someKey"":""someValue""}},""pinataContent"":{""hello"":""world""}}";
116+
var expectedBody = @"{""pinataOptions"":{""cidVersion"":1,""customPinPolicy"":{""regions"":[{""id"":""FRA1"",""desiredReplicationCount"":1}]},""wrapWithDirectory"":null,""hostNodes"":null},""pinataMetadata"":{""name"":""hello"",""keyvalues"":{""someKey"":""someValue""}},""pinataContent"":{""hello"":""world""}}";
117+
119118
this.server.ShouldHaveCalledPath("/pinning/pinJSONToIPFS")
120119
.WithVerb(Post)
121120
.WithExactBody(expectedBody);
@@ -157,27 +156,124 @@ public async Task pin_html_file()
157156
</body>
158157
</html>
159158
";
160-
var r = await this.client.Pinning.PinFileToIPFSAsync(payload =>
161-
{
162-
var file = new StringContent(html, Encoding.UTF8, MediaTypeNames.Text.Html)
163-
.AsPinataFile("index.html");
164-
165-
payload.Add(file);
166-
});
159+
var r = await this.client.Pinning.PinFileToIpfsAsync(payload =>
160+
{
161+
var file = new StringContent(html, Encoding.UTF8, MediaTypeNames.Text.Html);
162+
payload.AddPinataFile(file, "index.html");
163+
});
167164

168165

169166
this.server.ShouldHaveCalledPath("/pinning/pinFileToIPFS")
170-
.With(fc =>
167+
.WithVerb(Post);
168+
//.With(fc =>
169+
// {
170+
171+
// var cmc = fc.HttpRequestMessage.Content as CapturedMultipartContent;
172+
// foreach( var c in cmc )
173+
// {
174+
// var z = c.Headers.ContentDisposition;
175+
// }
176+
177+
178+
// var content = fc.HttpRequestMessage.Content as CapturedMultipartContent;
179+
180+
// var cds = content.Headers.ContentDisposition;
181+
// cds.Name.Should().Be("file");
182+
// cds.FileName.Should().Be("index.html");
183+
// return true;
184+
// });
185+
}
186+
187+
[Test]
188+
public async Task change_metadata()
189+
{
190+
this.server.RespondWith("OK");
191+
192+
var meta = new PinataMetadata
171193
{
172-
var content = fc.HttpRequestMessage.Content as CapturedMultipartContent;
194+
Name = "test3.html",
195+
KeyValues =
196+
{
197+
{"barbar", "jarjar"}
198+
}
199+
};
200+
var hash = "QmR9HwzakHVr67HFzzgJHoRjwzTTt4wtD6KU4NFe2ArYuj";
173201

174-
var cds = content.Headers.ContentDisposition;
175-
cds.Name.Should().Be("file");
176-
cds.FileName.Should().Be("index.html");
177-
return true;
178-
});
202+
var r = await this.client.Pinning.HashMetadataAsync(hash, meta);
203+
var s = await r.GetStringAsync();
204+
s.Should().Be("OK");
205+
206+
var expectedBody = @"{""ipfsPinHash"":""QmR9HwzakHVr67HFzzgJHoRjwzTTt4wtD6KU4NFe2ArYuj"",""name"":""test3.html"",""keyvalues"":{""barbar"":""jarjar""}}";
207+
208+
this.server.ShouldHaveCalledPath("/pinning/hashMetadata")
209+
.WithVerb(Put)
210+
.WithExactBody(expectedBody);
211+
}
212+
213+
[Test]
214+
public async Task change_hash_pinpolicy()
215+
{
216+
this.server.RespondWith("OK");
217+
218+
var policy = new PinPolicy();
219+
policy.AddOrUpdateRegion("NYC1", 1);
220+
policy.AddOrUpdateRegion("FRA1", 0);
221+
222+
var hash = "QmR9HwzakHVr67HFzzgJHoRjwzTTt4wtD6KU4NFe2ArYuj";
223+
224+
var expectedBody = @"{""ipfsPinHash"":""QmR9HwzakHVr67HFzzgJHoRjwzTTt4wtD6KU4NFe2ArYuj"",""newPinPolicy"":{""regions"":[{""id"":""NYC1"",""desiredReplicationCount"":1},{""id"":""FRA1"",""desiredReplicationCount"":0}]}}";
179225

226+
var r = await this.client.Pinning.HashPinPolicyAsync(hash, policy);
227+
var s = await r.GetStringAsync();
228+
s.Should().Be("OK");
180229

230+
this.server.ShouldHaveCalledPath("/pinning/hashPinPolicy")
231+
.WithVerb(Put)
232+
.WithExactBody(expectedBody);
233+
}
234+
235+
[Test]
236+
public async Task pin_by_hash()
237+
{
238+
this.server.RespondWithJsonTestFile();
239+
240+
var hash = "Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye";
241+
242+
var r = await this.client.Pinning.PinByHashAsync(hash);
243+
244+
var expectedBody = @"{""hashToPin"":""Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye"",""pinataMetadata"":null,""pinataOptions"":null}";
245+
246+
this.server.ShouldHaveCalledPath("/pinning/pinByHash")
247+
.WithVerb(Post)
248+
.WithExactBody(expectedBody);
249+
250+
await Verify(r);
251+
}
252+
253+
[Test]
254+
public async Task pin_jobs()
255+
{
256+
this.server.RespondWithJsonTestFile();
257+
258+
var filters = new
259+
{
260+
filter = new
261+
{
262+
sort = "ASC"
263+
},
264+
additionalFilter = new
265+
{
266+
limit = 5
267+
}
268+
};
269+
270+
var r = await this.client.Pinning.PinJobs(filters);
271+
272+
this.server.ShouldHaveCalledPath("/pinning/pinJobs")
273+
.WithVerb(Get)
274+
.WithQueryParams(filters);
275+
276+
await Verify(r);
181277
}
182278
}
183279
}

Source/Pinata.Client.Tests/PinningTests.new_user_pin_policy.server.json renamed to Source/Pinata.Client.Tests/EndpointTests/PinningTests.new_user_pin_policy.server.json

File renamed without changes.

Source/Pinata.Client.Tests/PinningTests.new_user_pin_policy.verified.json renamed to Source/Pinata.Client.Tests/EndpointTests/PinningTests.new_user_pin_policy.verified.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
Result: 'success',
2+
Result: success,
33
IsSuccess: true
44
}

0 commit comments

Comments
 (0)