Add additional test for testing failure after delete

This commit is contained in:
Gabe Kangas 2023-04-03 21:13:03 -07:00
parent 74f076f44b
commit ac7d655a14
No known key found for this signature in database
GPG key ID: 4345B2060657F330

View file

@ -11,149 +11,157 @@ const webhook = 'https://super.duper.cool.thing.biz/owncast';
const events = ['CHAT']; const events = ['CHAT'];
test('create webhook', async (done) => { test('create webhook', async (done) => {
const res = await sendAdminPayload('webhooks/create', { const res = await sendAdminPayload('webhooks/create', {
url: webhook, url: webhook,
events: events, events: events,
}); });
expect(res.body.url).toBe(webhook); expect(res.body.url).toBe(webhook);
expect(res.body.timestamp).toBeTruthy(); expect(res.body.timestamp).toBeTruthy();
expect(res.body.events).toStrictEqual(events); expect(res.body.events).toStrictEqual(events);
done(); done();
}); });
test('check webhooks', (done) => { test('check webhooks', (done) => {
getAdminResponse('webhooks').then((res) => {
getAdminResponse('webhooks') expect(res.body).toHaveLength(1);
.then((res) => { expect(res.body[0].url).toBe(webhook);
expect(res.body).toHaveLength(1); expect(res.body[0].events).toStrictEqual(events);
expect(res.body[0].url).toBe(webhook); webhookID = res.body[0].id;
expect(res.body[0].events).toStrictEqual(events); done();
webhookID = res.body[0].id; });
done();
});
}); });
test('delete webhook', async (done) => { test('delete webhook', async (done) => {
const res = await sendAdminPayload('webhooks/delete', { const res = await sendAdminPayload('webhooks/delete', {
id: webhookID, id: webhookID,
}); });
expect(res.body.success).toBe(true); expect(res.body.success).toBe(true);
done(); done();
}); });
test('check that webhook was deleted', (done) => { test('check that webhook was deleted', (done) => {
getAdminResponse('webhooks') getAdminResponse('webhooks').then((res) => {
.then((res) => { expect(res.body).toHaveLength(0);
expect(res.body).toHaveLength(0); done();
done(); });
});
}); });
test('create access token', async (done) => { test('create access token', async (done) => {
const name = 'Automated integration test'; const name = 'Automated integration test';
const scopes = [ const scopes = [
'CAN_SEND_SYSTEM_MESSAGES', 'CAN_SEND_SYSTEM_MESSAGES',
'CAN_SEND_MESSAGES', 'CAN_SEND_MESSAGES',
'HAS_ADMIN_ACCESS', 'HAS_ADMIN_ACCESS',
]; ];
const res = await sendAdminPayload('accesstokens/create', { const res = await sendAdminPayload('accesstokens/create', {
name: name, name: name,
scopes: scopes, scopes: scopes,
}); });
expect(res.body.accessToken).toBeTruthy(); expect(res.body.accessToken).toBeTruthy();
expect(res.body.createdAt).toBeTruthy(); expect(res.body.createdAt).toBeTruthy();
expect(res.body.displayName).toBe(name); expect(res.body.displayName).toBe(name);
expect(res.body.scopes).toStrictEqual(scopes); expect(res.body.scopes).toStrictEqual(scopes);
accessToken = res.body.accessToken; accessToken = res.body.accessToken;
done(); done();
}); });
test('check access tokens', async (done) => { test('check access tokens', async (done) => {
const res = await getAdminResponse('accesstokens'); const res = await getAdminResponse('accesstokens');
const tokenCheck = res.body.filter( const tokenCheck = res.body.filter(
(token) => token.accessToken === accessToken (token) => token.accessToken === accessToken
); );
expect(tokenCheck).toHaveLength(1); expect(tokenCheck).toHaveLength(1);
done(); done();
}); });
test('send a system message using access token', async (done) => { test('send a system message using access token', async (done) => {
const payload = { const payload = {
body: 'This is a test system message from the automated integration test', body: 'This is a test system message from the automated integration test',
}; };
const res = await request const res = await request
.post('/api/integrations/chat/system') .post('/api/integrations/chat/system')
.set('Authorization', 'Bearer ' + accessToken) .set('Authorization', 'Bearer ' + accessToken)
.send(payload) .send(payload)
.expect(200); .expect(200);
done(); done();
}); });
test('send an external integration message using access token', async (done) => { test('send an external integration message using access token', async (done) => {
const payload = { const payload = {
body: 'This is a test external message from the automated integration test', body: 'This is a test external message from the automated integration test',
}; };
const res = await request const res = await request
.post('/api/integrations/chat/send') .post('/api/integrations/chat/send')
.set('Authorization', 'Bearer ' + accessToken) .set('Authorization', 'Bearer ' + accessToken)
.send(payload) .send(payload)
.expect(200); .expect(200);
done(); done();
}); });
test('send an external integration action using access token', async (done) => { test('send an external integration action using access token', async (done) => {
const payload = { const payload = {
body: 'This is a test external action from the automated integration test', body: 'This is a test external action from the automated integration test',
}; };
await request await request
.post('/api/integrations/chat/action') .post('/api/integrations/chat/action')
.set('Authorization', 'Bearer ' + accessToken) .set('Authorization', 'Bearer ' + accessToken)
.send(payload) .send(payload)
.expect(200); .expect(200);
done(); done();
}); });
test('test fetch chat history using access token', async (done) => { test('test fetch chat history using access token', async (done) => {
const res = await request const res = await request
.get('/api/integrations/chat') .get('/api/integrations/chat')
.set('Authorization', 'Bearer ' + accessToken) .set('Authorization', 'Bearer ' + accessToken)
.expect(200); .expect(200);
done(); done();
}); });
test('test fetch chat history failure using invalid access token', async (done) => { test('test fetch chat history failure using invalid access token', async (done) => {
const res = await request const res = await request
.get('/api/integrations/chat') .get('/api/integrations/chat')
.set('Authorization', 'Bearer ' + 'invalidToken') .set('Authorization', 'Bearer ' + 'invalidToken')
.expect(401); .expect(401);
done(); done();
}); });
test('test fetch chat history OPTIONS request', async (done) => { test('test fetch chat history OPTIONS request', async (done) => {
const res = await request const res = await request
.options('/api/integrations/chat') .options('/api/integrations/chat')
.set('Authorization', 'Bearer ' + accessToken) .set('Authorization', 'Bearer ' + accessToken)
.expect(204); .expect(204);
done(); done();
}); });
test('delete access token', async (done) => { test('delete access token', async (done) => {
const res = await sendAdminPayload('accesstokens/delete', { const res = await sendAdminPayload('accesstokens/delete', {
token: accessToken, token: accessToken,
}); });
expect(res.body.success).toBe(true); expect(res.body.success).toBe(true);
done(); done();
}); });
test('check token delete was successful', async (done) => { test('check token delete was successful', async (done) => {
const res = await getAdminResponse('accesstokens'); const res = await getAdminResponse('accesstokens');
const tokenCheck = res.body.filter( const tokenCheck = res.body.filter(
(token) => token.accessToken === accessToken (token) => token.accessToken === accessToken
); );
expect(tokenCheck).toHaveLength(0); expect(tokenCheck).toHaveLength(0);
done(); done();
}); });
test('send an external integration action using access token expecting failure', async (done) => {
const payload = {
body: 'This is a test external action from the automated integration test',
};
await request
.post('/api/integrations/chat/action')
.set('Authorization', 'Bearer ' + accessToken)
.send(payload)
.expect(401);
done();
});