forked from karatelabs/karate
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupload.feature
54 lines (47 loc) · 2.31 KB
/
upload.feature
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
Feature: file upload end-point
Background:
* url demoBaseUrl
Scenario: upload file
Given path 'files'
# refer to the second scenario in this file for how to set the upload filename using the 'multipart file' syntax
And multipart field myFile = read('test.pdf')
And multipart field message = 'hello world'
When method post
Then status 200
And match response == { id: '#uuid', filename: 'myFile', message: 'hello world', contentType: 'application/octet-stream' }
And def id = response.id
Given path 'files', id
When method get
Then status 200
And match response == read('test.pdf')
And match header Content-Disposition contains 'attachment'
And match header Content-Disposition contains 'myFile'
And match header Content-Type == 'application/octet-stream'
# example of calling custom java code from karate
* def FileChecker = Java.type('com.intuit.karate.demo.util.FileChecker')
# example of parsing a string into json by karate
* json fileInfo = FileChecker.getMetadata(id)
* match fileInfo == { id: '#(id)', filename: 'myFile', message: 'hello world', contentType: 'application/octet-stream' }
Scenario: upload with filename and content-type specified
Given path 'files'
And multipart file myFile = { read: 'test.pdf', filename: 'upload-name.pdf', contentType: 'application/pdf' }
And multipart field message = 'hello world'
When method post
Then status 200
And match response == { id: '#uuid', filename: 'upload-name.pdf', message: 'hello world', contentType: 'application/pdf' }
And def id = response.id
Given path 'files', id
When method get
Then status 200
And match response == read('test.pdf')
And match header Content-Disposition contains 'attachment'
And match header Content-Disposition contains 'upload-name.pdf'
And match header Content-Type == 'application/pdf'
Scenario: upload multipart/mixed
Given path 'files', 'mixed'
And multipart field myJson = { text: 'hello world' }
And multipart file myFile = { read: 'test.pdf', filename: 'upload-name.pdf', contentType: 'application/pdf' }
And header Content-Type = 'multipart/mixed'
When method post
Then status 200
And match response == { id: '#uuid', filename: 'upload-name.pdf', message: 'hello world', contentType: 'application/pdf' }