-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: refactoring tests from old format to new
- Loading branch information
Mateusz Russak
committed
Dec 16, 2023
1 parent
bf1fcd2
commit 6b8777d
Showing
16 changed files
with
216 additions
and
255 deletions.
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
76 changes: 52 additions & 24 deletions
76
packages/server/src/app/actions/message/tests/pins.spec.js
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 |
---|---|---|
@@ -1,31 +1,59 @@ | ||
const assert = require('assert'); | ||
const api = require('../../tests/api'); | ||
const seeds = require('../../../../../tests/actions/seeds'); | ||
const seeds = require('./seeds'); | ||
|
||
module.exports = (connect) => { | ||
describe('messages:pins', () => { | ||
let channel; | ||
before(async () => { | ||
await seeds.run(); | ||
channel = await api.repo.channel.get({ name: 'main' }); | ||
}); | ||
describe('messages:pins', () => { | ||
let channel; | ||
let user; | ||
before(async () => { | ||
await seeds.run(); | ||
channel = await api.repo.channel.get({ name: 'main' }); | ||
user = await api.repo.user.get({ login: 'admin' }); | ||
}); | ||
after(async () => { | ||
await api.repo.close(); | ||
}); | ||
it('should return last added messsage', async () => { | ||
const ws = await connect(); | ||
const [msg, ret] = await ws.send({ | ||
type: 'messages:pins', | ||
channelId: channel._id.toHexString(), | ||
limit: 1, | ||
}); | ||
assert.equal(ret.type, 'response'); | ||
assert.equal(ret.status, 'ok'); | ||
assert.equal(ret.count, 1); | ||
assert.equal(msg.flat, 'Hello pinned'); | ||
ws.close(); | ||
}); | ||
it('should return pins with before filter'); | ||
it('should return pins with after filter'); | ||
|
||
it('should return last added messsage', async () => { | ||
const { res, data: [msg] } = await api.sendMessage({ | ||
type: 'messages:pins', | ||
channelId: channel.id, | ||
limit: 1, | ||
}, { userId: user.id }); | ||
assert.equal(res.type, 'response'); | ||
assert.equal(res.status, 'ok'); | ||
assert.equal(res.count, 1); | ||
assert.equal(msg.flat, 'Hello pinned'); | ||
}); | ||
|
||
it('should have no access to someones private channel', async () => { | ||
const deniedChannel = await api.repo.channel.get({ name: 'denied' }); | ||
const { res } = await api.sendMessage({ | ||
type: 'messages:pins', | ||
channelId: deniedChannel.id, | ||
limit: 1, | ||
}, { userId: user.id }); | ||
assert.equal(res.type, 'response'); | ||
assert.equal(res.status, 'error'); | ||
assert.equal(res.message, 'ACCESS_DENIED'); | ||
}); | ||
|
||
it('should ', async () => { | ||
const { res, data: [msg1, msg2] } = await api.sendMessage({ | ||
type: 'messages:pins', | ||
channelId: channel.id, | ||
limit: 2, | ||
}, { userId: user.id }); | ||
assert.equal(res.type, 'response'); | ||
assert.equal(res.status, 'ok'); | ||
const { res: res2, data: [msg] } = await api.sendMessage({ | ||
type: 'messages:pins', | ||
channelId: channel.id, | ||
after: msg1.id, | ||
limit: 1, | ||
}, { userId: user.id }); | ||
assert.equal(res2.type, 'response'); | ||
assert.equal(res2.status, 'ok'); | ||
assert.equal(msg.id, msg2.id); | ||
}); | ||
}; | ||
}); |
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,77 @@ | ||
const api = require('../../tests/api'); | ||
|
||
module.exports = { | ||
run: async () => { | ||
const member = await api.repo.user.get({ login: 'member' }); | ||
const admin = await api.repo.user.get({ login: 'admin' }); | ||
const channel = await api.repo.channel.get({ name: 'main' }); | ||
let deniedChannel = await api.repo.channel.get({ name: 'denied' }); | ||
if (!deniedChannel) { | ||
const id = await api.repo.channel.create({ name: 'denied', private: true, users: [] }); | ||
deniedChannel = await api.repo.channel.get({ id }); | ||
} | ||
const testChannel = await api.repo.channel.get({ name: 'test' }); | ||
if (!testChannel) await api.repo.channel.create({ name: 'test', private: false }); | ||
await api.repo.message.removeMany({ flat: 'Hello' }); | ||
await api.repo.badge.removeMany({}); | ||
await api.repo.message.createMany([ | ||
{ | ||
clientId: 1, | ||
message: { line: { text: 'Hello' } }, | ||
channel: 'main', | ||
channelId: channel.id, | ||
flat: 'Hello', | ||
userId: member.id, | ||
createdAt: new Date('2022-01-01'), | ||
}, | ||
{ | ||
clientId: 2, | ||
message: { line: { text: 'Hello' } }, | ||
channel: 'main', | ||
channelId: channel.id, | ||
flat: 'Hello', | ||
pinned: true, | ||
userId: admin.id, | ||
createdAt: new Date('2022-01-02'), | ||
}, | ||
{ | ||
clientId: 3, | ||
message: { line: { text: 'Hello' } }, | ||
channel: 'main', | ||
channelId: channel.id, | ||
flat: 'Hello', | ||
pinned: true, | ||
userId: member.id, | ||
createdAt: new Date('2022-01-03'), | ||
}, | ||
{ | ||
clientId: 4, | ||
message: { line: { text: 'Hello' } }, | ||
channel: 'main', | ||
channelId: channel.id, | ||
flat: 'Hello', | ||
userId: admin.id, | ||
createdAt: new Date('2022-01-04'), | ||
}, | ||
{ | ||
clientId: 5, | ||
message: { line: { text: 'Hello' } }, | ||
channel: 'main', | ||
channelId: channel.id, | ||
flat: 'Hello', | ||
userId: member.id, | ||
createdAt: new Date('2022-01-05'), | ||
}, | ||
{ | ||
clientId: 6, | ||
message: { line: { text: 'Hello' } }, | ||
channel: 'main', | ||
channelId: deniedChannel.id, | ||
pinned: true, | ||
flat: 'Hello', | ||
userId: member.id, | ||
createdAt: new Date('2022-01-05'), | ||
}, | ||
]); | ||
}, | ||
}; |
10 changes: 5 additions & 5 deletions
10
packages/server/tests/commands/help.spec.js → ...erver/src/app/commands/tests/help.spec.js
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
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,33 @@ | ||
const assert = require('assert'); | ||
const api = require('../../actions/tests/api'); | ||
|
||
describe('/me', () => { | ||
const NAME = 'Admin'; | ||
let channel; | ||
let admin; | ||
|
||
before(async () => { | ||
admin = await api.repo.user.get({ login: 'admin' }); | ||
channel = await api.repo.channel.get({ name: 'main' }); | ||
await api.repo.user.update({ login: 'admin' }, { name: 'Johny' }); | ||
}); | ||
|
||
after(async () => { | ||
await api.repo.user.update({ login: 'admin' }, { name: 'Admin' }); | ||
}); | ||
|
||
it('should return message with imformation about user', async () => { | ||
const { res, data: [user] } = await api.sendMessage({ | ||
type: 'command:execute', | ||
name: 'me', | ||
args: [], | ||
context: { | ||
channelId: channel.id, | ||
}, | ||
}, { userId: admin.id }); | ||
assert.equal(res.type, 'response'); | ||
assert.equal(res.status, 'ok'); | ||
|
||
assert.equal(user.type, 'message'); | ||
}); | ||
}); |
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,38 @@ | ||
const assert = require('assert'); | ||
const api = require('../../actions/tests/api'); | ||
|
||
describe('/name <name>', () => { | ||
const NAME = 'Admin'; | ||
let channel; | ||
let admin; | ||
|
||
before(async () => { | ||
admin = await api.repo.user.get({ login: 'admin' }); | ||
channel = await api.repo.channel.get({ name: 'main' }); | ||
await api.repo.user.update({ login: 'admin' }, { name: 'Johny' }); | ||
}); | ||
|
||
after(async () => { | ||
await api.repo.user.update({ login: 'admin' }, { name: 'Admin' }); | ||
}); | ||
|
||
it('should change users name', async () => { | ||
const { res, data: [user] } = await api.sendMessage({ | ||
type: 'command:execute', | ||
name: 'name', | ||
args: [NAME], | ||
context: { | ||
channelId: channel.id, | ||
}, | ||
}, { userId: admin.id }); | ||
assert.equal(res.type, 'response'); | ||
assert.equal(res.status, 'ok'); | ||
|
||
const state = await api.repo.user.get({ login: 'admin' }); | ||
assert.equal(state.name, NAME); | ||
assert.equal(user.type, 'user'); | ||
assert.equal(user.name, NAME); | ||
}); | ||
|
||
it('should inform others about change'); | ||
}); |
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
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.