remove uses of this in tests

GitOrigin-RevId: 2eea02c91358a7bb5e1d32c8990f793d6f794ac4
This commit is contained in:
Tim Alby 2022-01-10 10:50:25 +01:00 committed by Copybot
parent 5798011bce
commit d5c574360f
6 changed files with 167 additions and 190 deletions

View file

@ -5,46 +5,43 @@ const ChatClient = require('./helpers/ChatClient')
const ChatApp = require('./helpers/ChatApp')
describe('Deleting a message', async function () {
const projectId = ObjectId().toString()
const userId = ObjectId().toString()
const threadId = ObjectId().toString()
before(async function () {
this.project_id = ObjectId().toString()
this.user_id = ObjectId().toString()
this.thread_id = ObjectId().toString()
await ChatApp.ensureRunning()
})
describe('in a thread', async function () {
before(async function () {
const { response, body: message } = await ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
const { response } = await ChatClient.sendMessage(
projectId,
threadId,
userId,
'first message'
)
this.message = message
expect(response.statusCode).to.equal(201)
const { response: response2, body: message2 } =
const { response: response2, body: message } =
await ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
projectId,
threadId,
userId,
'deleted message'
)
this.message = message2
expect(response2.statusCode).to.equal(201)
const { response: response3 } = await ChatClient.deleteMessage(
this.project_id,
this.thread_id,
this.message.id
projectId,
threadId,
message.id
)
expect(response3.statusCode).to.equal(204)
})
it('should then remove the message from the threads', async function () {
const { response, body: threads } = await ChatClient.getThreads(
this.project_id
)
const { response, body: threads } = await ChatClient.getThreads(projectId)
expect(response.statusCode).to.equal(200)
expect(threads[this.thread_id].messages.length).to.equal(1)
expect(threads[threadId].messages.length).to.equal(1)
})
})
})

View file

@ -5,34 +5,32 @@ const ChatClient = require('./helpers/ChatClient')
const ChatApp = require('./helpers/ChatApp')
describe('Deleting a thread', async function () {
const projectId = ObjectId().toString()
const userId = ObjectId().toString()
before(async function () {
this.project_id = ObjectId().toString()
this.user_id = ObjectId().toString()
await ChatApp.ensureRunning()
})
describe('with a thread that is deleted', async function () {
const threadId = ObjectId().toString()
const content = 'deleted thread message'
before(async function () {
this.thread_id = ObjectId().toString()
this.content = 'deleted thread message'
const { response } = await ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
this.content
projectId,
threadId,
userId,
content
)
expect(response.statusCode).to.equal(201)
const { response: response2 } = await ChatClient.deleteThread(
this.project_id,
this.thread_id
projectId,
threadId
)
expect(response2.statusCode).to.equal(204)
})
it('should then not list the thread for the project', async function () {
const { response, body: threads } = await ChatClient.getThreads(
this.project_id
)
const { response, body: threads } = await ChatClient.getThreads(projectId)
expect(response.statusCode).to.equal(200)
expect(Object.keys(threads).length).to.equal(0)
})

View file

@ -5,47 +5,40 @@ const ChatClient = require('./helpers/ChatClient')
const ChatApp = require('./helpers/ChatApp')
describe('Editing a message', async function () {
const projectId = ObjectId().toString()
const userId = ObjectId().toString()
const threadId = ObjectId().toString()
before(async function () {
this.project_id = ObjectId().toString()
this.user_id = ObjectId().toString()
this.thread_id = ObjectId().toString()
await ChatApp.ensureRunning()
})
describe('in a thread', async function () {
const content = 'thread message'
const newContent = 'updated thread message'
before(async function () {
this.content = 'thread message'
this.new_content = 'updated thread message'
const { response, body: message } = await ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
this.content
projectId,
threadId,
userId,
content
)
this.message = message
expect(response.statusCode).to.equal(201)
expect(this.message.id).to.exist
expect(this.message.content).to.equal(this.content)
const { response: response2, body: newMessage } =
await ChatClient.editMessage(
this.project_id,
this.thread_id,
this.message.id,
this.new_content
expect(message.id).to.exist
expect(message.content).to.equal(content)
const { response: response2 } = await ChatClient.editMessage(
projectId,
threadId,
message.id,
newContent
)
this.new_message = newMessage
expect(response2.statusCode).to.equal(204)
})
it('should then list the updated message in the threads', async function () {
const { response, body: threads } = await ChatClient.getThreads(
this.project_id
)
const { response, body: threads } = await ChatClient.getThreads(projectId)
expect(response.statusCode).to.equal(200)
expect(threads[this.thread_id].messages.length).to.equal(1)
expect(threads[this.thread_id].messages[0].content).to.equal(
this.new_content
)
expect(threads[threadId].messages.length).to.equal(1)
expect(threads[threadId].messages[0].content).to.equal(newContent)
})
})
})

View file

@ -5,100 +5,99 @@ const ChatClient = require('./helpers/ChatClient')
const ChatApp = require('./helpers/ChatApp')
describe('Getting messages', async function () {
const userId1 = ObjectId().toString()
const userId2 = ObjectId().toString()
const content1 = 'foo bar'
const content2 = 'hello world'
before(async function () {
this.user_id1 = ObjectId().toString()
this.user_id2 = ObjectId().toString()
this.content1 = 'foo bar'
this.content2 = 'hello world'
await ChatApp.ensureRunning()
})
describe('globally', async function () {
const projectId = ObjectId().toString()
before(async function () {
this.project_id = ObjectId().toString()
const { response } = await ChatClient.sendGlobalMessage(
this.project_id,
this.user_id1,
this.content1
projectId,
userId1,
content1
)
expect(response.statusCode).to.equal(201)
const { response: response2 } = await ChatClient.sendGlobalMessage(
this.project_id,
this.user_id2,
this.content2
projectId,
userId2,
content2
)
expect(response2.statusCode).to.equal(201)
})
it('should contain the messages and populated users when getting the messages', async function () {
const { response, body: messages } = await ChatClient.getGlobalMessages(
this.project_id
projectId
)
expect(response.statusCode).to.equal(200)
expect(messages.length).to.equal(2)
messages.reverse()
expect(messages[0].content).to.equal(this.content1)
expect(messages[0].user_id).to.equal(this.user_id1)
expect(messages[1].content).to.equal(this.content2)
expect(messages[1].user_id).to.equal(this.user_id2)
expect(messages[0].content).to.equal(content1)
expect(messages[0].user_id).to.equal(userId1)
expect(messages[1].content).to.equal(content2)
expect(messages[1].user_id).to.equal(userId2)
})
})
describe('from all the threads', async function () {
const projectId = ObjectId().toString()
const threadId1 = ObjectId().toString()
const threadId2 = ObjectId().toString()
before(async function () {
this.project_id = ObjectId().toString()
this.thread_id1 = ObjectId().toString()
this.thread_id2 = ObjectId().toString()
const { response } = await ChatClient.sendMessage(
this.project_id,
this.thread_id1,
this.user_id1,
projectId,
threadId1,
userId1,
'one'
)
expect(response.statusCode).to.equal(201)
const { response: response2 } = await ChatClient.sendMessage(
this.project_id,
this.thread_id2,
this.user_id2,
projectId,
threadId2,
userId2,
'two'
)
expect(response2.statusCode).to.equal(201)
const { response: response3 } = await ChatClient.sendMessage(
this.project_id,
this.thread_id1,
this.user_id1,
projectId,
threadId1,
userId1,
'three'
)
expect(response3.statusCode).to.equal(201)
const { response: response4 } = await ChatClient.sendMessage(
this.project_id,
this.thread_id2,
this.user_id2,
projectId,
threadId2,
userId2,
'four'
)
expect(response4.statusCode).to.equal(201)
})
it('should contain a dictionary of threads with messages with populated users', async function () {
const { response, body: threads } = await ChatClient.getThreads(
this.project_id
)
const { response, body: threads } = await ChatClient.getThreads(projectId)
expect(response.statusCode).to.equal(200)
expect(Object.keys(threads).length).to.equal(2)
const thread1 = threads[this.thread_id1]
const thread1 = threads[threadId1]
expect(thread1.messages.length).to.equal(2)
const thread2 = threads[this.thread_id2]
const thread2 = threads[threadId2]
expect(thread2.messages.length).to.equal(2)
expect(thread1.messages[0].content).to.equal('one')
expect(thread1.messages[0].user_id).to.equal(this.user_id1)
expect(thread1.messages[0].user_id).to.equal(userId1)
expect(thread1.messages[1].content).to.equal('three')
expect(thread1.messages[1].user_id).to.equal(this.user_id1)
expect(thread1.messages[1].user_id).to.equal(userId1)
expect(thread2.messages[0].content).to.equal('two')
expect(thread2.messages[0].user_id).to.equal(this.user_id2)
expect(thread2.messages[0].user_id).to.equal(userId2)
expect(thread2.messages[1].content).to.equal('four')
expect(thread2.messages[1].user_id).to.equal(this.user_id2)
expect(thread2.messages[1].user_id).to.equal(userId2)
})
})
})

View file

@ -5,95 +5,89 @@ const ChatClient = require('./helpers/ChatClient')
const ChatApp = require('./helpers/ChatApp')
describe('Resolving a thread', async function () {
const projectId = ObjectId().toString()
const userId = ObjectId().toString()
before(async function () {
this.project_id = ObjectId().toString()
this.user_id = ObjectId().toString()
await ChatApp.ensureRunning()
})
describe('with a resolved thread', async function () {
const threadId = ObjectId().toString()
const content = 'resolved message'
before(async function () {
this.thread_id = ObjectId().toString()
this.content = 'resolved message'
const { response } = await ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
this.content
projectId,
threadId,
userId,
content
)
expect(response.statusCode).to.equal(201)
const { response: response2 } = await ChatClient.resolveThread(
this.project_id,
this.thread_id,
this.user_id
projectId,
threadId,
userId
)
expect(response2.statusCode).to.equal(204)
})
it('should then list the thread as resolved', async function () {
const { response, body: threads } = await ChatClient.getThreads(
this.project_id
)
const { response, body: threads } = await ChatClient.getThreads(projectId)
expect(response.statusCode).to.equal(200)
expect(threads[this.thread_id].resolved).to.equal(true)
expect(threads[this.thread_id].resolved_by_user_id).to.equal(this.user_id)
const resolvedAt = new Date(threads[this.thread_id].resolved_at)
expect(threads[threadId].resolved).to.equal(true)
expect(threads[threadId].resolved_by_user_id).to.equal(userId)
const resolvedAt = new Date(threads[threadId].resolved_at)
expect(new Date() - resolvedAt).to.be.below(1000)
})
})
describe('when a thread is not resolved', async function () {
const threadId = ObjectId().toString()
const content = 'open message'
before(async function () {
this.thread_id = ObjectId().toString()
this.content = 'open message'
const { response } = await ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
this.content
projectId,
threadId,
userId,
content
)
expect(response.statusCode).to.equal(201)
})
it('should not list the thread as resolved', async function () {
const { response, body: threads } = await ChatClient.getThreads(
this.project_id
)
const { response, body: threads } = await ChatClient.getThreads(projectId)
expect(response.statusCode).to.equal(200)
expect(threads[this.thread_id].resolved).to.be.undefined
expect(threads[threadId].resolved).to.be.undefined
})
})
describe('when a thread is resolved then reopened', async function () {
const threadId = ObjectId().toString()
const content = 'resolved message'
before(async function () {
this.thread_id = ObjectId().toString()
this.content = 'resolved message'
const { response } = await ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
this.content
projectId,
threadId,
userId,
content
)
expect(response.statusCode).to.equal(201)
const { response: response2 } = await ChatClient.resolveThread(
this.project_id,
this.thread_id,
this.user_id
projectId,
threadId,
userId
)
expect(response2.statusCode).to.equal(204)
const { response: response3 } = await ChatClient.reopenThread(
this.project_id,
this.thread_id
projectId,
threadId
)
expect(response3.statusCode).to.equal(204)
})
it('should not list the thread as resolved', async function () {
const { response, body: threads } = await ChatClient.getThreads(
this.project_id
)
const { response, body: threads } = await ChatClient.getThreads(projectId)
expect(response.statusCode).to.equal(200)
expect(threads[this.thread_id].resolved).to.be.undefined
expect(threads[threadId].resolved).to.be.undefined
})
})
})

View file

@ -10,61 +10,59 @@ describe('Sending a message', async function () {
})
describe('globally', async function () {
const projectId = ObjectId().toString()
const userId = ObjectId().toString()
const content = 'global message'
before(async function () {
this.project_id = ObjectId().toString()
this.user_id = ObjectId().toString()
this.content = 'global message'
const { response, body } = await ChatClient.sendGlobalMessage(
this.project_id,
this.user_id,
this.content
projectId,
userId,
content
)
expect(response.statusCode).to.equal(201)
expect(body.content).to.equal(this.content)
expect(body.user_id).to.equal(this.user_id)
expect(body.room_id).to.equal(this.project_id)
expect(body.content).to.equal(content)
expect(body.user_id).to.equal(userId)
expect(body.room_id).to.equal(projectId)
})
it('should then list the message in the project messages', async function () {
const { response, body: messages } = await ChatClient.getGlobalMessages(
this.project_id
projectId
)
expect(response.statusCode).to.equal(200)
expect(messages.length).to.equal(1)
expect(messages[0].content).to.equal(this.content)
expect(messages[0].content).to.equal(content)
})
})
describe('to a thread', async function () {
const projectId = ObjectId().toString()
const userId = ObjectId().toString()
const threadId = ObjectId().toString()
const content = 'thread message'
before(async function () {
this.project_id = ObjectId().toString()
this.user_id = ObjectId().toString()
this.thread_id = ObjectId().toString()
this.content = 'thread message'
const { response, body } = await ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
this.content
projectId,
threadId,
userId,
content
)
expect(response.statusCode).to.equal(201)
expect(body.content).to.equal(this.content)
expect(body.user_id).to.equal(this.user_id)
expect(body.room_id).to.equal(this.project_id)
expect(body.content).to.equal(content)
expect(body.user_id).to.equal(userId)
expect(body.room_id).to.equal(projectId)
})
it('should then list the message in the threads', async function () {
const { response, body: threads } = await ChatClient.getThreads(
this.project_id
)
const { response, body: threads } = await ChatClient.getThreads(projectId)
expect(response.statusCode).to.equal(200)
expect(threads[this.thread_id].messages.length).to.equal(1)
expect(threads[this.thread_id].messages[0].content).to.equal(this.content)
expect(threads[threadId].messages.length).to.equal(1)
expect(threads[threadId].messages[0].content).to.equal(content)
})
it('should not appear in the global messages', async function () {
const { response, body: messages } = await ChatClient.getGlobalMessages(
this.project_id
projectId
)
expect(response.statusCode).to.equal(200)
expect(messages.length).to.equal(0)
@ -72,17 +70,15 @@ describe('Sending a message', async function () {
})
describe('failure cases', async function () {
before(async function () {
this.project_id = ObjectId().toString()
this.user_id = ObjectId().toString()
this.thread_id = ObjectId().toString()
})
const projectId = ObjectId().toString()
const userId = ObjectId().toString()
const threadId = ObjectId().toString()
describe('with a malformed user_id', async function () {
describe('with a malformed userId', async function () {
it('should return a graceful error', async function () {
const { response, body } = await ChatClient.sendMessage(
this.project_id,
this.thread_id,
projectId,
threadId,
'malformed-user',
'content'
)
@ -91,12 +87,12 @@ describe('Sending a message', async function () {
})
})
describe('with a malformed project_id', async function () {
describe('with a malformed projectId', async function () {
it('should return a graceful error', async function () {
const { response, body } = await ChatClient.sendMessage(
'malformed-project',
this.thread_id,
this.user_id,
threadId,
userId,
'content'
)
expect(response.statusCode).to.equal(400)
@ -104,12 +100,12 @@ describe('Sending a message', async function () {
})
})
describe('with a malformed thread_id', async function () {
describe('with a malformed threadId', async function () {
it('should return a graceful error', async function () {
const { response, body } = await ChatClient.sendMessage(
this.project_id,
projectId,
'malformed-thread-id',
this.user_id,
userId,
'content'
)
expect(response.statusCode).to.equal(400)
@ -120,9 +116,9 @@ describe('Sending a message', async function () {
describe('with no content', async function () {
it('should return a graceful error', async function () {
const { response, body } = await ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
projectId,
threadId,
userId,
null
)
expect(response.statusCode).to.equal(400)
@ -134,9 +130,9 @@ describe('Sending a message', async function () {
it('should return a graceful error', async function () {
const content = '-'.repeat(10 * 1024 + 1)
const { response, body } = await ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
projectId,
threadId,
userId,
content
)
expect(response.statusCode).to.equal(400)