-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.ts
231 lines (202 loc) · 8.48 KB
/
tests.ts
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import anyTest, { TestInterface } from 'ava'
import ExoPlatformWrapper from '../src'
import { Space } from '../src/types/Space'
import { SpaceSubscription, SpaceVisibility } from '../src/types/Space'
import { Activity, Comment } from '../src/types/Activity'
interface ConfigObject {
EXO_HOSTNAME: string
EXO_PATH: string
EXO_SECURE_PROTOCOL: string
EXO_CIPHERS: string
EXO_USERNAME: string
EXO_PASSWORD: string
}
// Load a custom test object and load the tests setup
const test = anyTest as TestInterface<{
exoWrapper: ExoPlatformWrapper
/** Pre-test setup */
setup: {
RANDOM_ID: string
config: ConfigObject
}
/** Any data passed from test to test */
passedData: {
space: Space
activity: Activity
userActivity: Activity
comment: Comment
}
}>
const randomStr = (length = 6) => [...Array(length)].map(() => Math.random().toString(36)[2]).join('')
const loadConfig = () => {
let missing = []
if (!process.env.EXO_HOSTNAME) missing.push('EXO_HOSTNAME')
if (!process.env.EXO_USERNAME) missing.push('EXO_USERNAME')
if (!process.env.EXO_PASSWORD) missing.push('EXO_PASSWORD')
if (missing.length > 0) throw new Error(`Missing configuration environment variables: ${missing}.`)
const { EXO_HOSTNAME, EXO_PATH, EXO_USERNAME, EXO_PASSWORD, EXO_SECURE_PROTOCOL, EXO_CIPHERS } = process.env
return <ConfigObject>{ EXO_HOSTNAME, EXO_PATH, EXO_USERNAME, EXO_PASSWORD, EXO_SECURE_PROTOCOL, EXO_CIPHERS }
}
// Hook to configure tests context and load configuration
test.before(t => {
const config = loadConfig()
t.context.setup = {
RANDOM_ID: randomStr(),
config
}
t.context.exoWrapper = new ExoPlatformWrapper(config.EXO_HOSTNAME, config.EXO_PATH, config.EXO_SECURE_PROTOCOL, config.EXO_CIPHERS)
t.context.passedData = <any>{}
})
test.serial('Login to the platform', t =>
t.notThrowsAsync(t.context.exoWrapper.login(t.context.setup.config.EXO_USERNAME, t.context.setup.config.EXO_PASSWORD)))
// SPACE: `create(spaceData: SpacePartial)`
test.serial('Create a space', async t => {
const displayName = `space-testing-${t.context.setup.RANDOM_ID}`
const description = `space-testing-description-${t.context.setup.RANDOM_ID}`
const space = await t.context.exoWrapper.space.create({
displayName,
description,
subscription: SpaceSubscription.close,
visibility: SpaceVisibility.hidden
})
t.is(space.displayName, displayName)
t.is(space.description, description)
t.context.passedData.space = space
})
// SPACE: `list(limit: number = 20, offset: number = 0)`
test.serial('List available spaces', async t => {
const { spaces } = await t.context.exoWrapper.space.list()
t.true(spaces.length > 0)
t.truthy(spaces.find(x => x.displayName))
})
// SPACE: `getData(spaceId: string)`
test.serial('Get space data', async t => {
const space = await t.context.exoWrapper.space.getData(t.context.passedData.space.id)
t.is(space.displayName, t.context.passedData.space.displayName)
t.is(space.description, t.context.passedData.space.description)
})
// SPACE: `edit(spaceId: string, spaceData: SpacePartial)`
test.serial('Edit a space', async t => {
const displayName = `${t.context.passedData.space.displayName}-edited`
const description = `${t.context.passedData.space.description}-edited`
const space = await t.context.exoWrapper.space.edit(t.context.passedData.space.id, {
displayName,
description,
subscription: SpaceSubscription.open,
visibility: SpaceVisibility.hidden
})
t.is(space.displayName, displayName)
t.is(space.description, description)
t.context.passedData.space = space
})
// SPACE: `publish(spaceId: string, message: string)`
test.serial('Publish in a space', async t => {
const message = `Testing-${t.context.setup.RANDOM_ID}`
const activity = await t.context.exoWrapper.space.publish(
t.context.passedData.space.id,
message
)
t.is(activity.title, message)
t.context.passedData.activity = activity
})
// ACTIVITY: `read(activityId: string)`
test.serial('Read an activity', async t => {
const activity = await t.context.exoWrapper.activity.read(t.context.passedData.activity.id)
t.is(activity.title, t.context.passedData.activity.title)
})
// ACTIVITY: `edit(activityId: string, message: string)`
test.serial('Edit an activity', async t => {
const message = `${t.context.passedData.activity.title}-edited`
const activity = await t.context.exoWrapper.activity.edit(
t.context.passedData.activity.id,
message
)
t.is(activity.title, message)
t.context.passedData.activity = activity
})
// ACTIVITY-LIKE: `add(activityId: string)`
test.serial('Like an activity', t =>
t.notThrowsAsync(t.context.exoWrapper.activity.like.add(t.context.passedData.activity.id))
)
// ACTIVITY-LIKE: `list(activityId: string, limit: number = 20, offset: number = 0)`
test.serial('List activity likers', async t => {
const { likes } = await t.context.exoWrapper.activity.like.list(t.context.passedData.activity.id)
t.is(likes.length, 1)
})
// ACTIVITY-LIKE: `remove(activityId: string, username: string | undefined = this.username || undefined)`
test.serial('Unlike an activity', t =>
t.notThrowsAsync(t.context.exoWrapper.activity.like.remove(t.context.passedData.activity.id))
)
// ACTIVITY-COMMENT: `add(activityId: string, message: string)`
test.serial('Comment an activity', async t => {
const message = `Testing-comment-${t.context.setup.RANDOM_ID}`
const comment = await t.context.exoWrapper.activity.comment.add(
t.context.passedData.activity.id,
message
)
t.is(comment.title, message)
t.context.passedData.comment = comment
})
// ACTIVITY-COMMENT: `edit(commentId: string, message: string)`
test.serial('Edit a comment', async t => {
const message = `${t.context.passedData.comment.title}-edited`
const comment = await t.context.exoWrapper.activity.comment.edit(
t.context.passedData.comment.id,
message
)
t.is(comment.title, message)
t.context.passedData.comment = comment
})
// ACTIVITY-COMMENT: `list(activityId: string, limit: number = 20, offset: number = 0)`
test.serial('List activity comments', async t => {
const { comments } = await t.context.exoWrapper.activity.comment.list(t.context.passedData.activity.id)
t.is(comments.length, 1)
t.is(comments[0].title, t.context.passedData.comment.title)
})
// FIXME: The API always respond with a 500 error
// ACTIVITY-COMMENT: `remove(commentId: string)`
test.todo('Remove a comment from an activity')
// test.serial('Remove a comment from an activity', t =>
// t.notThrowsAsync(t.context.exoWrapper.activity.comment.remove(t.context.passedData.comment.id))
// )
// ACTIVITY: `readStream(), limit: number = 20, offset: number = 0`
test.serial('Read an activity stream', async t => {
const { activities } = await t.context.exoWrapper.activity.readStream()
const activity = activities.find(x => x.title)
t.truthy(activity)
t.is((<Activity>activity).title, t.context.passedData.activity.title)
})
// SPACE: `readStream(spaceId: string, limit: number = 20, offset: number = 0)`
test.serial('Read space stream', async t => {
const { activities } = await t.context.exoWrapper.space.readStream(t.context.passedData.space.id)
const activity = activities.find(x => x.title)
t.truthy(activity)
t.is((<Activity>activity).title, t.context.passedData.activity.title)
})
// ACTIVITY: `remove(activityId: string)`
test.serial('Remove an activity', t =>
t.notThrowsAsync(t.context.exoWrapper.activity.remove(t.context.passedData.activity.id))
)
// SPACE: `remove(spaceId: string)`
test.serial('Remove a space', async t =>
t.notThrowsAsync(t.context.exoWrapper.space.remove(t.context.passedData.space.id)))
// USER: `list(limit: number = 20, offset: number = 0)`
test.serial('List available users', async t => {
const { users } = await t.context.exoWrapper.user.list()
t.true(users.length >= 1)
})
// USER: `publish(message: string)`
test.serial('Publish on a user stream', async t => {
const message = `Testing-user-${t.context.setup.RANDOM_ID}`
const activity = await t.context.exoWrapper.user.publish(message)
t.is(activity.title, message)
t.context.passedData.userActivity = activity
})
// USER: `readStream(username: string | undefined = this.username || undefined, limit: number = 20, offset: number = 0)`
test.serial('Read an user stream', async t => {
const { activities } = await t.context.exoWrapper.user.readStream()
const activity = activities.find(x => x.title)
t.truthy(activity)
t.is((<Activity>activity).title, t.context.passedData.userActivity.title)
return t.notThrowsAsync(t.context.exoWrapper.activity.remove(t.context.passedData.userActivity.id))
})