-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(chat-service): add test case for attachment file (#1396)
add test case of has many relation for attachment file GH-1395
- Loading branch information
1 parent
ddfef35
commit f4373d4
Showing
2 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
services/chat-service/src/__tests__/unit/message-repository.unit.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import {expect} from '@loopback/testlab'; | ||
import {setUpApplication} from '../acceptance/helper'; | ||
import {ChatApplication} from '../application'; | ||
import {MessageRepository} from '../../repositories'; | ||
describe('supports @has many', () => { | ||
let app: ChatApplication; | ||
let messageRepo: MessageRepository; | ||
const messageObj = { | ||
body: 'Test message', | ||
channelId: 'test channel', | ||
channelType: 'testchannel type', | ||
}; | ||
before('setupApplication', async () => { | ||
({app} = await setUpApplication()); | ||
}); | ||
after(async () => { | ||
await app.stop(); | ||
}); | ||
before(givenRepositories); | ||
afterEach(deleteMockData); | ||
it('fetch messages with associated message file', async () => { | ||
const message = await messageRepo.create(messageObj); | ||
const file1 = await messageRepo.attachmentFiles(message.id).create({ | ||
fileKey: 'test_file1.txt', | ||
}); | ||
const file2 = await messageRepo.attachmentFiles(message.id).create({ | ||
fileKey: 'test_file2.txt', | ||
}); | ||
const filter = { | ||
where: {id: message.id}, | ||
include: [{relation: 'attachmentFiles'}], | ||
}; | ||
const messagesWithFiles = await messageRepo.find(filter); | ||
const messageFiles = messagesWithFiles[0].attachmentFiles; | ||
expect(messagesWithFiles[0].id).to.equal(message.id); | ||
expect(messageFiles[0].fileKey).to.equal(file1.fileKey); | ||
expect(messageFiles[1].fileKey).to.equal(file2.fileKey); | ||
}); | ||
async function givenRepositories() { | ||
messageRepo = await app.getRepository(MessageRepository); | ||
} | ||
async function deleteMockData() { | ||
await messageRepo.deleteAllHard(); | ||
} | ||
}); |