|
1 | 1 | import { module, test } from 'qunit';
|
2 | 2 | import { setupTest } from 'ember-qunit';
|
3 | 3 | import Channel from 'hyperchannel/models/channel';
|
| 4 | +import Message from 'hyperchannel/models/message'; |
4 | 5 | import { xmppAccount } from '../../fixtures/accounts';
|
5 | 6 |
|
6 | 7 | module('Unit | Service | sockethub xmpp', function(hooks) {
|
@@ -99,6 +100,35 @@ module('Unit | Service | sockethub xmpp', function(hooks) {
|
99 | 100 | assert.equal(channel.messages.lastObject.content, 'hello world');
|
100 | 101 | });
|
101 | 102 |
|
| 103 | + test('#addMessageToChannel updates pending status when receiving an outgoing message', function(assert) { |
| 104 | + const channel = new Channel({ account: xmppAccount, name: '[email protected]' }); |
| 105 | + const outgoingMessage = new Message({ |
| 106 | + type: 'message-chat', |
| 107 | + date: new Date(), |
| 108 | + nickname: 'jimmy', |
| 109 | + content: 'yo, gang!', |
| 110 | + pending: true |
| 111 | + }); |
| 112 | + channel.messages.pushObject(outgoingMessage); |
| 113 | + |
| 114 | + const comsService = this.owner.factoryFor('service:coms').create({ |
| 115 | + accounts: [ xmppAccount ], channels: [ channel ] |
| 116 | + }); |
| 117 | + const service = this.owner.factoryFor('service:sockethub-xmpp').create({ coms: comsService }); |
| 118 | + |
| 119 | + const message = { |
| 120 | + actor: { '@id': '[email protected]/jimmy', '@type': 'person', displayName: 'jimmy' }, |
| 121 | + target: { '@id': '[email protected]', '@type': 'room' }, |
| 122 | + object: { '@type': 'message', content: 'yo, gang!' } |
| 123 | + }; |
| 124 | + |
| 125 | + service.addMessageToChannel(message); |
| 126 | + |
| 127 | + assert.equal(channel.messages.filterBy('nickname', 'jimmy').length, 1); |
| 128 | + assert.equal(channel.messages.lastObject.content, 'yo, gang!'); |
| 129 | + assert.notOk(channel.messages.lastObject.pending); |
| 130 | + }); |
| 131 | + |
102 | 132 | test('#createUserChannel', function(assert) {
|
103 | 133 | const comsService = this.owner.factoryFor('service:coms').create({
|
104 | 134 | accounts: [ xmppAccount ]
|
|
0 commit comments