Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix member ordering for creating member based channels #591

Merged
merged 3 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ export class StreamChat<
getChannelByMembers = (channelType: string, custom: ChannelData<ChannelType>) => {
// Check if the channel already exists.
// Only allow 1 channel object per cid
const membersStr = custom.members?.sort().join(',');
const membersStr = [...(custom.members || [])].sort().join(',');
const tempCid = `${channelType}:!members-${membersStr}`;

if (!membersStr) {
Expand Down
67 changes: 0 additions & 67 deletions test/integration/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
} from './utils';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { get } from 'https';

const expect = chai.expect;

Expand Down Expand Up @@ -90,72 +89,6 @@ describe('query by frozen', function () {
});
});

describe('Channels - Constructor', function () {
const client = getServerTestClient();

it('canonical form', function (done) {
const channel = client.channel('messaging', '123', { cool: true });
expect(channel.cid).to.eql('messaging:123');
expect(channel.id).to.eql('123');
expect(channel.data).to.eql({ cool: true });
done();
});

it('default options', function (done) {
const channel = client.channel('messaging', '123');
expect(channel.cid).to.eql('messaging:123');
expect(channel.id).to.eql('123');
done();
});

it('null ID no options', function (done) {
const channel = client.channel('messaging', null);
expect(channel.id).to.eq(undefined);
done();
});

it('undefined ID no options', function (done) {
const channel = client.channel('messaging', undefined);
expect(channel.id).to.eql(undefined);
expect(channel.data).to.eql({});
done();
});

it('short version with options', function (done) {
const channel = client.channel('messaging', { members: ['tommaso', 'thierry'] });
expect(channel.data).to.eql({ members: ['tommaso', 'thierry'] });
expect(channel.id).to.eql(undefined);
done();
});

it('null ID with options', function (done) {
const channel = client.channel('messaging', null, {
members: ['tommaso', 'thierry'],
});
expect(channel.data).to.eql({ members: ['tommaso', 'thierry'] });
expect(channel.id).to.eql(undefined);
done();
});

it('empty ID with options', function (done) {
const channel = client.channel('messaging', '', {
members: ['tommaso', 'thierry'],
});
expect(channel.data).to.eql({ members: ['tommaso', 'thierry'] });
expect(channel.id).to.eql(undefined);
done();
});

it('empty ID with options', function (done) {
const channel = client.channel('messaging', undefined, {
members: ['tommaso', 'thierry'],
});
expect(channel.data).to.eql({ members: ['tommaso', 'thierry'] });
expect(channel.id).to.eql(undefined);
done();
});
});

describe('Channels - Create', function () {
const johnID = `john-${uuidv4()}`;

Expand Down
66 changes: 66 additions & 0 deletions test/unit/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,72 @@ describe('Channel _handleChannelEvent', function () {
});
});

describe('Channels - Constructor', function () {
const client = new StreamChat('key', 'secret');

it('canonical form', function (done) {
const channel = client.channel('messaging', '123', { cool: true });
expect(channel.cid).to.eql('messaging:123');
expect(channel.id).to.eql('123');
expect(channel.data).to.eql({ cool: true });
done();
});

it('default options', function (done) {
const channel = client.channel('messaging', '123');
expect(channel.cid).to.eql('messaging:123');
expect(channel.id).to.eql('123');
done();
});

it('null ID no options', function (done) {
const channel = client.channel('messaging', null);
expect(channel.id).to.eq(undefined);
done();
});

it('undefined ID no options', function (done) {
const channel = client.channel('messaging', undefined);
expect(channel.id).to.eql(undefined);
expect(channel.data).to.eql({});
done();
});

it('short version with options', function (done) {
const channel = client.channel('messaging', { members: ['tommaso', 'thierry'] });
expect(channel.data).to.eql({ members: ['tommaso', 'thierry'] });
expect(channel.id).to.eql(undefined);
done();
});

it('null ID with options', function (done) {
const channel = client.channel('messaging', null, {
members: ['tommaso', 'thierry'],
});
expect(channel.data).to.eql({ members: ['tommaso', 'thierry'] });
expect(channel.id).to.eql(undefined);
done();
});

it('empty ID with options', function (done) {
const channel = client.channel('messaging', '', {
members: ['tommaso', 'thierry'],
});
expect(channel.data).to.eql({ members: ['tommaso', 'thierry'] });
expect(channel.id).to.eql(undefined);
done();
});

it('empty ID with options', function (done) {
const channel = client.channel('messaging', undefined, {
members: ['tommaso', 'thierry'],
});
expect(channel.data).to.eql({ members: ['tommaso', 'thierry'] });
expect(channel.id).to.eql(undefined);
done();
});
});

describe('Ensure single channel per cid on client activeChannels state', () => {
const clientVish = new StreamChat('', '');
const user = { id: 'user' };
Expand Down