-
Notifications
You must be signed in to change notification settings - Fork 1
/
testSetup.spec.ts
155 lines (140 loc) · 4.51 KB
/
testSetup.spec.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
import * as css from '@solid/community-server'
import { getAuthenticatedFetch } from 'css-authn/dist/7.x'
import { IncomingMessage, Server, ServerResponse } from 'http'
import MailDev from 'maildev'
import app from '../app'
import { port } from '../config'
import { EmailVerification, Integration } from '../config/sequelize'
import { createRandomAccount } from '../helpers'
let server: Server<typeof IncomingMessage, typeof ServerResponse>
let authenticatedFetch: typeof fetch
let authenticatedFetchNoNotifications: typeof fetch
let person: {
idp: string
podUrl: string
webId: string
username: string
password: string
email: string
}
let personNoNotifications: {
idp: string
podUrl: string
webId: string
username: string
password: string
email: string
}
let cssServer: css.App
let cssServerNoNotifications: css.App
before(async function () {
this.timeout(60000)
const start = Date.now()
// eslint-disable-next-line no-console
console.log('Starting CSS server')
// Community Solid Server (CSS) set up following example in https://github.com/CommunitySolidServer/hello-world-component/blob/main/test/integration/Server.test.ts
cssServer = await new css.AppRunner().create({
loaderProperties: {
mainModulePath: css.joinFilePath(__dirname, '../../'), // ?
typeChecking: false, // ?
dumpErrorState: false, // disable CSS error dump
},
config: css.joinFilePath(__dirname, './css-default-config.json'), // CSS config
variableBindings: {},
// CSS cli options
// https://github.com/CommunitySolidServer/CommunitySolidServer/tree/main#-parameters
shorthand: {
port: 3456,
loggingLevel: 'off',
seedConfig: css.joinFilePath(__dirname, './css-pod-seed.json'), // set up some Solid accounts
},
})
await cssServer.start()
// eslint-disable-next-line no-console
console.log('CSS server started in', (Date.now() - start) / 1000, 'seconds')
})
after(async () => {
await cssServer.stop()
})
before(async function () {
this.timeout(60000)
const start = Date.now()
// eslint-disable-next-line no-console
console.log('Starting CSS server without notifications')
// Community Solid Server (CSS) set up following example in https://github.com/CommunitySolidServer/hello-world-component/blob/main/test/integration/Server.test.ts
cssServerNoNotifications = await new css.AppRunner().create({
loaderProperties: {
mainModulePath: css.joinFilePath(__dirname, '../../'), // ?
typeChecking: false, // ?
dumpErrorState: false, // disable CSS error dump
},
config: css.joinFilePath(__dirname, './css-config-no-notifications.json'), // CSS config
variableBindings: {},
// CSS cli options
// https://github.com/CommunitySolidServer/CommunitySolidServer/tree/main#-parameters
shorthand: {
port: 3457,
loggingLevel: 'off',
// seededPodConfigJson: css.joinFilePath(__dirname, './css-pod-seed.json'), // set up some Solid accounts
},
})
await cssServerNoNotifications.start()
// eslint-disable-next-line no-console
console.log('CSS server started in', (Date.now() - start) / 1000, 'seconds')
})
after(async () => {
await cssServerNoNotifications.stop()
})
before(done => {
server = app.listen(port, done)
})
after(done => {
server.close(done)
})
// run maildev server
let maildev: InstanceType<typeof MailDev>
before(done => {
maildev = new MailDev({
silent: true, // Set to false if you want to see server logs
disableWeb: true, // Disable the web interface for testing
})
maildev.listen(done)
})
after(done => {
maildev.close(done)
})
// clear the database before each test
beforeEach(async () => {
await EmailVerification.destroy({ truncate: true })
await Integration.destroy({ truncate: true })
})
/**
* Before each test, create a new account and authenticate to it
*/
beforeEach(async () => {
person = await createRandomAccount({ solidServer: 'http://localhost:3456' })
authenticatedFetch = await getAuthenticatedFetch({
email: person.email,
password: person.password,
provider: 'http://localhost:3456',
})
})
beforeEach(async () => {
personNoNotifications = await createRandomAccount({
solidServer: 'http://localhost:3457',
})
authenticatedFetchNoNotifications = await getAuthenticatedFetch({
email: personNoNotifications.email,
password: personNoNotifications.password,
provider: 'http://localhost:3457',
})
})
export {
authenticatedFetch,
authenticatedFetchNoNotifications,
cssServer,
cssServerNoNotifications,
person,
personNoNotifications,
server,
}