|
6 | 6 |
|
7 | 7 | describe 'Uploading' do |
8 | 8 | describe 'Uploading' do |
9 | | - describe 'POST /v2/bot/audienceGroup/upload/byFile' do |
| 9 | + describe 'PUT /v2/bot/audienceGroup/upload/byFile' do |
10 | 10 | let(:client) { Line::Bot::V2::ManageAudience::ApiBlobClient.new(channel_access_token: channel_access_token) } |
11 | 11 | let(:file_path) { 'spec/fixtures/line/bot/v2/sample_user_ids.txt' } |
12 | 12 | let(:file) { File.open(file_path) } |
13 | 13 |
|
14 | 14 | it 'uploads a file to the audience successfully' do |
15 | 15 | stub_request(:put, "https://api-data.line.me/v2/bot/audienceGroup/upload/byFile") |
16 | | - .with( |
17 | | - headers: { |
18 | | - 'Authorization' => "Bearer #{channel_access_token}", |
19 | | - 'Content-Type' => %r{multipart/form-data} # webmock doesn't support multipart/form-data so we use regex |
20 | | - } |
21 | | - ) |
22 | | - .to_return(status: 202, body: '', headers: {}) |
| 16 | + .with do |request| |
| 17 | + expect(request.headers['Authorization']).to eq("Bearer #{channel_access_token}") |
| 18 | + # Ensure it's multipart/form-data (with boundary) |
| 19 | + expect(request.headers['Content-Type']).to match(%r{\Amultipart/form-data; boundary=.+}) |
| 20 | + |
| 21 | + # Check if 'uploadDescription' part exists |
| 22 | + expect(request.body).to include('Content-Disposition: form-data; name="uploadDescription"') |
| 23 | + expect(request.body).to include('Test Audience') |
| 24 | + |
| 25 | + # Check if 'audienceGroupId' part exists |
| 26 | + expect(request.body).to include('Content-Disposition: form-data; name="audienceGroupId"') |
| 27 | + expect(request.body).to include('1234') |
| 28 | + |
| 29 | + # file part |
| 30 | + expect(request.body).to include('Content-Disposition: form-data; name="file"; filename="sample_user_ids.txt"') |
| 31 | + # body must contain content type text/plain |
| 32 | + expect(request.body).to include('Content-Type: text/plain') |
| 33 | + expect(request.body).to include('U4af4980627') |
| 34 | + expect(request.body).to include('U4af4980628') |
| 35 | + end |
| 36 | + .to_return(status: 202, body: '{}', headers: {}) |
23 | 37 |
|
24 | 38 | response_body, status_code, headers = client.add_user_ids_to_audience_with_http_info( |
25 | 39 | file: file, |
|
28 | 42 | ) |
29 | 43 |
|
30 | 44 | expect(status_code).to eq(202) |
31 | | - expect(response_body).to be_empty |
| 45 | + expect(response_body).to eq("{}") |
| 46 | + end |
| 47 | + end |
| 48 | + |
| 49 | + describe 'POST /v2/bot/audienceGroup/upload/byFile' do |
| 50 | + let(:client) { Line::Bot::V2::ManageAudience::ApiBlobClient.new(channel_access_token: channel_access_token) } |
| 51 | + let(:file_path) { 'spec/fixtures/line/bot/v2/sample_user_ids.txt' } |
| 52 | + let(:file) { File.open(file_path) } |
| 53 | + let(:response_body) do |
| 54 | + { |
| 55 | + "audienceGroupId": 1234567890123, |
| 56 | + "createRoute": "MESSAGING_API", |
| 57 | + "type": "UPLOAD", |
| 58 | + "description": "audienceGroupName_01", |
| 59 | + "created": 1613700237, |
| 60 | + "permission": "READ_WRITE", |
| 61 | + "expireTimestamp": 1629252237, |
| 62 | + "isIfaAudience": false |
| 63 | + }.to_json |
| 64 | + end |
| 65 | + |
| 66 | + it 'uploads a file to the audience successfully' do |
| 67 | + stub_request(:post, "https://api-data.line.me/v2/bot/audienceGroup/upload/byFile") |
| 68 | + .with do |request| |
| 69 | + expect(request.headers['Authorization']).to eq("Bearer #{channel_access_token}") |
| 70 | + # Ensure it's multipart/form-data (with boundary) |
| 71 | + expect(request.headers['Content-Type']).to match(%r{\Amultipart/form-data; boundary=.+}) |
| 72 | + |
| 73 | + # Check if 'uploadDescription' part exists |
| 74 | + expect(request.body).to include('Content-Disposition: form-data; name="uploadDescription"') |
| 75 | + expect(request.body).to include('Test Audience') |
| 76 | + |
| 77 | + # file part |
| 78 | + expect(request.body).to include('Content-Disposition: form-data; name="file"; filename="sample_user_ids.txt"') |
| 79 | + # body must contain content type text/plain |
| 80 | + expect(request.body).to include('Content-Type: text/plain') |
| 81 | + expect(request.body).to include('U4af4980627') |
| 82 | + expect(request.body).to include('U4af4980628') |
| 83 | + end |
| 84 | + .to_return(status: 202, body: response_body, headers: {}) |
| 85 | + |
| 86 | + body, status_code, headers = client.create_audience_for_uploading_user_ids_with_http_info( |
| 87 | + file: file, |
| 88 | + upload_description: 'Test Audience' |
| 89 | + ) |
| 90 | + |
| 91 | + expect(status_code).to eq(202) |
| 92 | + expect(body.audience_group_id).to eq(1234567890123) |
32 | 93 | end |
33 | 94 | end |
34 | 95 |
|
|
0 commit comments