Skip to content

Commit 0331d5d

Browse files
committed
feat(responses): add delete method to remove responses
1 parent ab6a982 commit 0331d5d

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ Each one of them encapsulates the operations related to it (like listing, updati
198198

199199
### Responses
200200

201+
#### `responses.delete({ uid, ids })`
202+
203+
- Delete responses to a form.
204+
- `uid`: Unique ID for the form.
205+
- `ids`: Tokens of the responses to delete. You can list up to 1000 tokens. Accepts either a string or an array of strings.
206+
201207
#### `responses.list({ uid, pageSize, since, until, after, before, ids, completed, sort, query, fields })`
202208

203209
- Returns form responses and date and time of form landing and submission.

src/responses.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ class Responses {
55
this._http = _http
66
}
77

8+
delete ({ uid, ids }) {
9+
return this._http.request({
10+
method: 'delete',
11+
url: `/forms/${uid}/responses`,
12+
params: {
13+
included_tokens: toCSL(ids)
14+
}
15+
})
16+
}
17+
818
list ({ uid, pageSize, since, until, after, before, ids, completed, sort, query, fields } = {}) {
919
return this._http.request({
1020
method: 'get',

tests/unit/responses.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,15 @@ test('List responses with the given filters', () => {
2525
expect(params.get('page_size')).toBe('15')
2626
expect(params.get('after')).toBe('12345')
2727
})
28+
29+
test('Delete responses has the correct path and method when given string for `ids`', () => {
30+
responsesRequest.delete({ uid: 2, ids: '123' })
31+
expect(fetch.mock.calls[0][1].method).toBe('delete')
32+
expect(fetch.mock.calls[0][0]).toBe(`${API_BASE_URL}/forms/2/responses?included_tokens=123`)
33+
})
34+
35+
test('Delete responses has the correct path and method when given array of strings for `ids`', () => {
36+
responsesRequest.delete({ uid: 2, ids: ['123', '456', '789'] })
37+
expect(fetch.mock.calls[0][1].method).toBe('delete')
38+
expect(fetch.mock.calls[0][0]).toBe(`${API_BASE_URL}/forms/2/responses?included_tokens=123%2C456%2C789`)
39+
})

0 commit comments

Comments
 (0)