|
1 | | -using System.Linq; |
2 | 1 | using System.Net.Http; |
3 | 2 | using System.Net.Mime; |
4 | 3 | using System.Text; |
5 | 4 | using System.Threading.Tasks; |
6 | 5 | using FluentAssertions; |
7 | | -using Flurl.Http.Content; |
8 | 6 | using NUnit.Framework; |
9 | 7 | using static System.Net.Http.HttpMethod; |
10 | 8 |
|
11 | | -namespace Pinata.Client.Tests |
| 9 | +namespace Pinata.Client.Tests.EndpointTests |
12 | 10 | { |
13 | 11 | public class PinningTests : MockServerTest |
14 | 12 | { |
@@ -66,7 +64,7 @@ public async Task pin_json_content_with_options() |
66 | 64 |
|
67 | 65 | var r = await this.client.Pinning.PinJsonToIpfsAsync(content, meta, opts); |
68 | 66 |
|
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""}}}"; |
70 | 68 |
|
71 | 69 | this.server.ShouldHaveCalledPath("/pinning/pinJSONToIPFS") |
72 | 70 | .WithVerb(Post) |
@@ -115,7 +113,8 @@ public async Task pin_json_object_with_options() |
115 | 113 | }; |
116 | 114 | var r = await this.client.Pinning.PinJsonToIpfsAsync(body, meta, opts); |
117 | 115 |
|
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 | + |
119 | 118 | this.server.ShouldHaveCalledPath("/pinning/pinJSONToIPFS") |
120 | 119 | .WithVerb(Post) |
121 | 120 | .WithExactBody(expectedBody); |
@@ -157,27 +156,124 @@ public async Task pin_html_file() |
157 | 156 | </body> |
158 | 157 | </html> |
159 | 158 | "; |
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 | + }); |
167 | 164 |
|
168 | 165 |
|
169 | 166 | 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 |
171 | 193 | { |
172 | | - var content = fc.HttpRequestMessage.Content as CapturedMultipartContent; |
| 194 | + Name = "test3.html", |
| 195 | + KeyValues = |
| 196 | + { |
| 197 | + {"barbar", "jarjar"} |
| 198 | + } |
| 199 | + }; |
| 200 | + var hash = "QmR9HwzakHVr67HFzzgJHoRjwzTTt4wtD6KU4NFe2ArYuj"; |
173 | 201 |
|
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}]}}"; |
179 | 225 |
|
| 226 | + var r = await this.client.Pinning.HashPinPolicyAsync(hash, policy); |
| 227 | + var s = await r.GetStringAsync(); |
| 228 | + s.Should().Be("OK"); |
180 | 229 |
|
| 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); |
181 | 277 | } |
182 | 278 | } |
183 | 279 | } |
0 commit comments