Skip to content
This repository was archived by the owner on May 28, 2024. It is now read-only.

Commit a8ea495

Browse files
authored
Merge pull request #25 from deskbookers/revert-24-ft-744-store-user-language
Revert "feat: add setLanguage / setTimezone functions"
2 parents 0952152 + 89345fc commit a8ea495

File tree

11 files changed

+36
-167
lines changed

11 files changed

+36
-167
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ for (let workplace of workplaces) {
4343
* [`retrieve()`](docs/account.md#retrieve)
4444
* [`contexts(params)`](docs/account.md#contextsparams)
4545
* [`menu(context)`](docs/account.md#menucontext)
46-
* [`setLanguage(language)`](docs/account.md#setlanguagelanguage)
47-
* [`setTimezone(timezone)`](docs/account.md#settimezonetimezone)
4846
* workplaces
4947
* [`urgency(id, params)`](docs/workplaces.md#urgencyid-params)
5048
* events

docs/account.md

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -204,37 +204,3 @@ context | String | Context code | Yes
204204
}]
205205
}
206206
```
207-
208-
## `setLanguage(language)`
209-
Store user language.
210-
211-
```js
212-
await deskbookers.account.setLanguage('en-gb')
213-
```
214-
215-
### Arguments
216-
Name | Type | Description | Required
217-
--- | --- | --- | ---
218-
language | String | Language code | Yes
219-
220-
### Example response
221-
```json
222-
true
223-
```
224-
225-
## `setTimezone(timezone)`
226-
Store user timezone.
227-
228-
```js
229-
await deskbookers.account.setTimezone('Europe/Amsterdam')
230-
```
231-
232-
### Arguments
233-
Name | Type | Description | Required
234-
--- | --- | --- | ---
235-
timezone | String | Timezone | Yes
236-
237-
### Example response
238-
```json
239-
true
240-
```
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export default class DeskbookersError extends Error {
22
constructor (message) {
3-
super(message)
4-
this.name = 'DeskbookersError'
3+
super()
4+
this.type = 'DeskbookersError'
5+
this.message = message
56
}
67
}

src/InvalidResponseError.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/resources/Account.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -136,26 +136,6 @@ export default class Account extends Resource {
136136
}
137137
}
138138

139-
async setLanguage (language) {
140-
return await this.request({
141-
method: 'POST',
142-
path: 'user/language',
143-
params: {
144-
lang: language
145-
}
146-
})
147-
}
148-
149-
async setTimezone (timezone) {
150-
return await this.request({
151-
method: 'POST',
152-
path: 'user/timezone',
153-
params: {
154-
timezone
155-
}
156-
})
157-
}
158-
159139
async contexts ({ ...params } = {}) {
160140
return await this.request({
161141
method: 'GET',

src/resources/Events.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Resource from './Resource'
2-
import DeskbookersError from '../DeskbookersError'
32

43
export default class Events extends Resource {
54
constructor (api) {
@@ -15,7 +14,7 @@ export default class Events extends Resource {
1514

1615
async retrieve (tabId = null, limit = 10) {
1716
if (!tabId) {
18-
throw new DeskbookersError('No tab id')
17+
throw new Error('No tab id')
1918
}
2019

2120
const events = await this.request({
@@ -24,7 +23,7 @@ export default class Events extends Resource {
2423
})
2524

2625
if (!events.length) {
27-
throw new DeskbookersError('No events')
26+
throw new Error('No events')
2827
}
2928

3029
// Get most recent event id

src/resources/Resource.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { signer, formatArgs } from '../utils/requests'
2-
import DeskbookersError from '../DeskbookersError'
3-
import InvalidResponseError from '../InvalidResponseError'
42

53
export default class Resource {
64
constructor (api) {
@@ -60,15 +58,7 @@ export default class Resource {
6058
}
6159

6260
async parseResponse (response) {
63-
// In case of an incorrect response we want to know that the raw response
64-
// was. Because of this we can't use response.json()
65-
let text = await response.text()
66-
let data
67-
try {
68-
data = JSON.parse(text)
69-
} catch (e) {
70-
throw new InvalidResponseError(text)
71-
}
61+
const data = await response.json()
7262

7363
const {
7464
data: dataProp,
@@ -86,26 +76,26 @@ export default class Resource {
8676
const { errors } = result
8777
if (errors) {
8878
for (let error in errors) {
89-
throw new DeskbookersError(errors[error])
79+
throw new Error(errors[error])
9080
}
9181
}
9282
return result
9383

9484
// If "error" exists in response
9585
} else if (error) {
9686
const msg = data.errorMessage || 'An error occurred'
97-
throw new DeskbookersError(msg)
87+
throw new Error(msg)
9888

9989
// If "errors" exists in response
10090
} else if (errors) {
10191
for (let error in errors) {
10292
const msg = errors[error].title || errors[error].detail
103-
throw new DeskbookersError(msg)
93+
throw new Error(msg)
10494
}
10595
}
10696

10797
// Reject
108-
throw new DeskbookersError('Invalid response received')
98+
throw new Error('Invalid response received')
10999
}
110100

111101
prepareRequest (url, options, args) {

src/resources/Workplaces.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Resource from './Resource'
2-
import DeskbookersError from '../DeskbookersError'
32

43
export default class Workplaces extends Resource {
54
constructor (api) {
@@ -18,6 +17,7 @@ export default class Workplaces extends Resource {
1817
async list (params) {
1918
// Build query from params
2019
// if Location, etc.
20+
2121
return await this.request({
2222
method: 'GET',
2323
path: '/search/results',
@@ -32,9 +32,7 @@ export default class Workplaces extends Resource {
3232
if (!isArray && typeof params === 'object') {
3333
params = [ params ]
3434
} else if (!isArray) {
35-
throw new DeskbookersError(
36-
'Parameters must be an Object or Array'
37-
)
35+
throw new Error('Parameters must be an Object or Array')
3836
}
3937

4038
return await this.request({

test/account.js

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,87 +5,53 @@ import Deskbookers from '../src'
55
import faker from 'faker'
66
dotenv.load()
77

8+
const deskbookers = new Deskbookers({
9+
https: process.env.API_HTTPS === 'true',
10+
host: process.env.API_HOST
11+
})
12+
813
const {
914
LOGIN_EMAIL,
1015
LOGIN_PASSWORD
1116
} = process.env
1217

13-
function client () {
14-
return new Deskbookers({
15-
https: process.env.API_HTTPS === 'true',
16-
host: process.env.API_HOST
17-
})
18-
}
19-
20-
async function login (t, deskbookers, dbg) {
21-
const user = await deskbookers.account.login(
22-
LOGIN_EMAIL,
23-
LOGIN_PASSWORD
24-
)
25-
26-
t.truthy(deskbookers.session)
27-
28-
return user
29-
}
30-
3118
test('Login', async t => {
32-
const user = await login(t, client(), 'Login')
33-
34-
t.truthy(user.id)
19+
const login = await deskbookers.account.login(LOGIN_EMAIL, LOGIN_PASSWORD)
20+
t.truthy(login.id)
3521
})
3622

3723
test('Signup', async t => {
38-
const signup = await client().account.signup({
24+
const signup = await deskbookers.account.signup({
3925
firstName: faker.name.firstName(),
4026
lastName: faker.name.lastName(),
4127
email: faker.internet.email(),
4228
password: 'p4ssw0rd'
4329
})
44-
4530
t.truthy(signup.id)
4631
})
4732

4833
test('Forgot', async t => {
49-
const forgot = await client().account.forgot(faker.internet.email())
34+
const forgot = await deskbookers.account.forgot(faker.internet.email())
5035

5136
t.truthy(forgot)
5237
})
5338

5439
test('Logout', async t => {
55-
const deskbookers = client()
56-
await login(t, deskbookers, 'Logout')
40+
// Login and store session
41+
await deskbookers.account.login(
42+
process.env.LOGIN_EMAIL,
43+
process.env.LOGIN_PASSWORD
44+
)
5745

5846
t.truthy(deskbookers.session)
5947

6048
// Logout
6149
await deskbookers.account.logout()
62-
6350
t.is(deskbookers.session, null)
6451
})
6552

6653
test('Retrieve', async t => {
67-
const deskbookers = client()
68-
69-
// Should fail whilte logged out
7054
t.throws(deskbookers.account.retrieve())
71-
72-
await login(t, deskbookers, 'Retrieve')
73-
74-
// Should succeed while logged in
55+
await deskbookers.account.login(LOGIN_EMAIL, LOGIN_PASSWORD)
7556
t.notThrows(deskbookers.account.retrieve())
7657
})
77-
78-
test('Set language', async t => {
79-
// Login
80-
const deskbookers = client()
81-
await login(t, deskbookers, 'Set language')
82-
83-
// Set language test
84-
for (let language of ['en-gb']) { // 'en-gb', 'nl-nl', 'de-de']) {
85-
const result = await deskbookers.account.setLanguage(language)
86-
const user = await deskbookers.account.retrieve()
87-
88-
t.truthy(result)
89-
t.is(user.language, language)
90-
}
91-
})

test/events.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@ import test from 'ava'
44
import Deskbookers from '../src'
55
dotenv.load()
66

7-
function client () {
8-
return new Deskbookers({
9-
https: process.env.API_HTTPS === 'true',
10-
host: process.env.API_HOST
11-
})
12-
}
7+
const deskbookers = new Deskbookers({
8+
https: process.env.API_HTTPS === 'true',
9+
host: process.env.API_HOST
10+
})
1311

1412
test('Unread count', async t => {
15-
const deskbookers = client()
16-
1713
await deskbookers.account.login(
1814
process.env.LOGIN_EMAIL,
1915
process.env.LOGIN_PASSWORD
@@ -24,8 +20,6 @@ test('Unread count', async t => {
2420
})
2521

2622
test('Events', async t => {
27-
const deskbookers = client()
28-
2923
await deskbookers.account.login(
3024
process.env.LOGIN_EMAIL,
3125
process.env.LOGIN_PASSWORD
@@ -42,8 +36,6 @@ test('Events', async t => {
4236
})
4337

4438
test('Can retrieve first page containing all events', async t => {
45-
const deskbookers = client()
46-
4739
await deskbookers.account.login(
4840
process.env.LOGIN_EMAIL,
4941
process.env.LOGIN_PASSWORD
@@ -55,8 +47,6 @@ test('Can retrieve first page containing all events', async t => {
5547
})
5648

5749
test('Can mark all events as read', async t => {
58-
const deskbookers = client()
59-
6050
await deskbookers.account.login(
6151
process.env.LOGIN_EMAIL,
6252
process.env.LOGIN_PASSWORD
@@ -66,3 +56,4 @@ test('Can mark all events as read', async t => {
6656

6757
t.truthy(res)
6858
})
59+

0 commit comments

Comments
 (0)