Skip to content

Commit 6e39aed

Browse files
committed
Use cucumber docstring to mock file upload
1 parent 3798c01 commit 6e39aed

File tree

3 files changed

+9
-65
lines changed

3 files changed

+9
-65
lines changed

Diff for: features/attendee_import.feature

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
Feature: Attendee Importation
22
Scenario: POST /attendees
3-
When I make a POST request to "/attendees" with file "attendees.csv"
3+
When I make a POST request to "/attendees" with file:
4+
"""
5+
token,display_name,
6+
"fccfc8bfa07643a1ca8015cbe74f5f17","Aotoki",
7+
"93dc46e553ac602b0d6c6d7307e523f1","Danny",
8+
"""
49
Then the response status should be 200

Diff for: features/support/apiSteps.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Then, When } from '@cucumber/cucumber'
22
import { WorkerWorld } from './world'
33
import { expect } from 'expect'
4-
import { readFileSync } from 'node:fs'
54

65
const nestedAttribute = (obj: any, path: string) =>
76
path.split('.').reduce((prev, curr) => prev?.[curr], obj)
@@ -22,11 +21,10 @@ When(
2221
)
2322

2423
When(
25-
'I make a POST request to {string} with file {string}',
26-
async function (this: WorkerWorld, path: string, filePath: string) {
24+
'I make a POST request to {string} with file:',
25+
async function (this: WorkerWorld, path: string, content: string) {
2726
const formData = new FormData()
28-
const file = readFileSync(`${__dirname}/data/${filePath}`, 'utf8')
29-
formData.append('file', file)
27+
formData.append('file', content)
3028
this.apiResponse = await this.api.fetch(`https://ccip.opass.app${path}`, {
3129
method: 'POST',
3230
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },

Diff for: features/support/data/attendees.csv

-59
This file was deleted.

0 commit comments

Comments
 (0)