roster: avoid race-condition by waiting for contacts to be fetched

before creating any new ones
This commit is contained in:
JC Brand 2020-01-24 14:46:46 +01:00
parent 9a2ebceb1b
commit c05e8110c4
2 changed files with 2 additions and 0 deletions

View File

@ -112,6 +112,7 @@
* </query>
* </iq>
*/
await test_utils.waitForRoster(_converse, 'all', 0);
expect(_converse.roster.sendContactAddIQ).toHaveBeenCalled();
expect(sent_stanza.toLocaleString()).toBe(
`<iq id="${IQ_id}" type="set" xmlns="jabber:client">`+

View File

@ -516,6 +516,7 @@ converse.plugins.add('converse-roster', {
* @param { Object } attributes - Any additional attributes to be stored on the user's model.
*/
async addContactToRoster (jid, name, groups, attributes) {
await _converse.api.waitUntil('rosterContactsFetched');
groups = groups || [];
try {
await this.sendContactAddIQ(jid, name, groups);