Skip to content

Commit a043f92

Browse files
authored
Merge pull request #15 from blinkmobile/ON-2254
ON-2254 # Added forms.getForm() function
2 parents e7e5cbd + 86efed9 commit a043f92

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Added
6+
7+
- `forms.getForm()` function
8+
59
## 0.2.2 (2018-09-25)
610

711
### Added

docs/forms.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,39 @@ forms.getSubmissionData(formId, submissionId)
100100
}
101101
```
102102

103+
## Get Single Form
104+
105+
### Example
106+
107+
```javascript
108+
const formId = 1
109+
forms.getForm(formId)
110+
.then((form) => {
111+
// Use form here...
112+
})
113+
```
114+
115+
### Parameters
116+
117+
| Parameter | Required | Type | Description
118+
|---|---|---|---|
119+
| `formId` | Yes | `number` | The exact id of the form you wish to get |
120+
121+
### Result (Resolved Promise)
122+
123+
```json
124+
{
125+
"id": 1,
126+
"name": "testsform",
127+
"description": "a form",
128+
"organisationId": "0101010101010",
129+
"elements": [],
130+
"isAuthenticated": false,
131+
"isPublished": true,
132+
"submissionEvents": []
133+
}
134+
```
135+
103136
## Search Forms
104137

105138
### Example

lib/forms.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
/* ::
55
import type {
6+
Form,
67
ConstructorOptions,
78
FormsSearchOptions,
89
FormsSearchResult,
@@ -105,4 +106,12 @@ module.exports = class Forms extends OneBlinkAPI {
105106

106107
return super.searchRequest(`/forms`, searchParams)
107108
}
109+
110+
getForm (formId /* : ?mixed */) /* : Promise<Form> */ {
111+
if (typeof formId !== 'number') {
112+
return Promise.reject(new TypeError('Must supply "formId" as a number'))
113+
}
114+
115+
return super.getRequest(`/forms/${formId}`)
116+
}
108117
}

tests/lib/forms.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,19 @@ describe('Forms SDK Class', () => {
9797
})
9898
})
9999
})
100+
101+
describe('getForm()', () => {
102+
const Forms = require('../../lib/forms.js')
103+
const forms = new Forms({
104+
accessKey: '123',
105+
secretKey: 'abc',
106+
oneBlinkAPIOrigin: 'https://domain.api.com'
107+
})
108+
109+
describe('should reject with correct validation errors for', () => {
110+
test('"formId"', () => {
111+
return expect(forms.getForm('123')).rejects.toThrow('Must supply "formId" as a number')
112+
})
113+
})
114+
})
100115
})

0 commit comments

Comments
 (0)