|
1 | 1 | require "spec_helper" |
2 | 2 |
|
3 | | -describe "client creates a finalized transfer with 5 files" do |
| 3 | +describe "transfer integration" do |
4 | 4 | around do |example| |
5 | 5 | WebMock.allow_net_connect! |
6 | 6 | example.run |
7 | 7 | WebMock.disable_net_connect! |
8 | 8 | end |
9 | 9 |
|
10 | | - it "works" do |
| 10 | + it "Create a client, a transfer, it uploads files and finalizes the transfer" do |
11 | 11 | client = WeTransfer::Client.new(api_key: ENV.fetch("WT_API_KEY")) |
12 | 12 |
|
13 | 13 | client.create_transfer(message: "test transfer") do |transfer| |
14 | | - transfer.add_file(name: "test_file_1", size: 10) |
15 | | - transfer.add_file(name: "test_file_2", size: 10, io: StringIO.new("#" * 10)) |
16 | | - # transfer.add_file(name: "test_file_3", size: 10) |
17 | | - # test_file_4 is a file of more than 1 chunk |
18 | | - transfer.add_file(name: "test_file_4", io: File.open('spec/fixtures/Japan-01.jpg')) |
19 | | - transfer.add_file(name: "test_file_5", io: File.open("Gemfile")) |
| 14 | + transfer.add_file(name: "small_file", size: 80) |
| 15 | + transfer.add_file(name: "small_file_with_io", size: 10, io: StringIO.new("#" * 10)) |
| 16 | + transfer.add_file(name: "multi_chunk_big_file", io: File.open('spec/fixtures/Japan-01.jpg')) |
20 | 17 | end |
21 | 18 |
|
22 | 19 | transfer = client.transfer |
23 | | - # these next expectations should check against state (that it is persisted, and the corresponding flag is truthy) |
| 20 | + |
| 21 | + expect(transfer.url) |
| 22 | + .to be_nil |
| 23 | + |
24 | 24 | expect(transfer.id.nil?).to eq false |
25 | 25 | expect(transfer.state).to eq "uploading" |
26 | 26 | expect(transfer.files.none? { |f| f.id.nil? }).to eq true |
27 | 27 |
|
28 | | - transfer.upload_file(name: "test_file_1", io: StringIO.new("#" * 10)) |
29 | | - transfer.complete_file(name: "test_file_1") |
30 | | - |
31 | | - transfer.upload_file(name: "test_file_2") |
32 | | - transfer.complete_file(name: "test_file_2") |
| 28 | + transfer.upload_file(name: "small_file", io: StringIO.new("#" * 80)) |
| 29 | + transfer.complete_file(name: "small_file") |
33 | 30 |
|
34 | | - # upload "test_file_3" using Faraday to express we aren't bound to using the SDK for uploading |
35 | | - # transfer.add_file(name: "test_file_3", size: 10) |
| 31 | + transfer.upload_file(name: "small_file_with_io") |
| 32 | + transfer.complete_file(name: "small_file_with_io") |
36 | 33 |
|
37 | | - transfer.upload_file(name: "test_file_4") |
38 | | - transfer.complete_file(name: "test_file_4") |
| 34 | + transfer.upload_file(name: "multi_chunk_big_file") |
| 35 | + transfer.complete_file(name: "multi_chunk_big_file") |
39 | 36 |
|
40 | | - transfer.upload_file(name: "test_file_5") |
41 | | - transfer.complete_file(name: "test_file_5") |
| 37 | + transfer.finalize |
42 | 38 |
|
43 | 39 | expect(transfer.state).to eq "processing" |
44 | 40 |
|
45 | | - transfer.finalize |
46 | | - |
47 | | - # If the server on the other end is done, the transfer will become downloadable. |
48 | | - # But I don't feel like `sleep`ing |
49 | | - # expect(transfer.state).to eq "downloadable" |
| 41 | + # Your transfer is available (after processing) at `transfer.url` |
| 42 | + expect(transfer.url) |
| 43 | + .to match %r|https://we.tl/t-| |
50 | 44 | end |
51 | 45 | end |
0 commit comments