2019-03-24 02:10:00 +01:00
|
|
|
import request from 'supertest'
|
2019-04-12 16:26:13 +02:00
|
|
|
import server from '../src/server'
|
2019-03-07 14:41:27 +01:00
|
|
|
|
2019-03-24 02:10:00 +01:00
|
|
|
afterAll(done => {
|
|
|
|
server.close(done)
|
|
|
|
})
|
2019-03-07 14:41:27 +01:00
|
|
|
|
2019-05-17 11:41:55 +02:00
|
|
|
describe('GET /', () => {
|
|
|
|
it('responds with success', async () => {
|
|
|
|
const response = await request(server).get('/')
|
2019-06-17 16:43:17 +02:00
|
|
|
expect(response.status).toBe(200)
|
2019-05-17 11:41:55 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-03-24 02:10:00 +01:00
|
|
|
describe('POST /api/v1/urlcheck', () => {
|
2019-09-06 13:50:36 +02:00
|
|
|
it('responds with json on http://', async () => {
|
|
|
|
const response = await request(server)
|
|
|
|
.post('/api/v1/urlcheck')
|
|
|
|
.send({ url: 'https://oceanprotocol.com/tech-whitepaper.pdf' })
|
|
|
|
expect(response.status).toBe(200)
|
|
|
|
expect(response.body).toBeTruthy()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('responds with json on ipfs://', async () => {
|
|
|
|
const response = await request(server)
|
|
|
|
.post('/api/v1/urlcheck')
|
|
|
|
.send({
|
|
|
|
url: 'ipfs://QmQfpdcMWnLTXKKW9GPV7NgtEugghgD6HgzSF6gSrp2mL9'
|
|
|
|
})
|
2019-05-31 16:00:27 +02:00
|
|
|
expect(response.status).toBe(200)
|
2019-09-06 13:50:36 +02:00
|
|
|
expect(response.body).toBeTruthy()
|
2019-04-30 19:19:28 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('responds with error message when url is missing', async () => {
|
|
|
|
const response = await request(server).post('/api/v1/urlcheck')
|
|
|
|
const text = await JSON.parse(response.text)
|
|
|
|
expect(text.message).toBe('missing url')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-07-05 15:30:19 +02:00
|
|
|
describe('POST /api/v1/report', () => {
|
2019-09-11 00:59:56 +02:00
|
|
|
const msg = {
|
|
|
|
to: 'test@example.com',
|
|
|
|
from: 'test@example.com',
|
|
|
|
subject: 'My Subject',
|
|
|
|
text: 'Text',
|
|
|
|
html: '<strong>HTML</strong>'
|
|
|
|
}
|
|
|
|
|
|
|
|
it('responds with json', async () => {
|
|
|
|
const response = await request(server)
|
|
|
|
.post('/api/v1/report')
|
|
|
|
.send({ msg })
|
|
|
|
expect(response.status).toBe(200)
|
|
|
|
expect(response.body).toBeTruthy()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('responds with error', async () => {
|
|
|
|
const response = await request(server)
|
|
|
|
.post('/api/v1/report')
|
|
|
|
.send({ msg: 'Hello World' })
|
|
|
|
expect(response.text).toBe(
|
|
|
|
"undefined - Cannot create property 'isMultiple' on string 'Hello World'"
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-07-05 15:30:19 +02:00
|
|
|
it('responds with error message when message is missing', async () => {
|
|
|
|
const response = await request(server).post('/api/v1/report')
|
|
|
|
const text = await JSON.parse(response.text)
|
|
|
|
expect(text.message).toBe('missing message')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-04-30 19:19:28 +02:00
|
|
|
describe('Errors', () => {
|
|
|
|
it('responds with 404 on unknown path', async () => {
|
|
|
|
const response = await request(server).post('/whatever')
|
2019-05-31 16:00:27 +02:00
|
|
|
expect(response.status).toBe(404)
|
2019-03-24 02:10:00 +01:00
|
|
|
})
|
|
|
|
})
|