Repository: leancloud/js-realtime-sdk
Pull request #606 (2019-03-18 09:43:16)

feat(conversation): unique is true by default
related issue: leancloud/paas#1024

codecov-io: # [Codecov](https://codecov.io/gh/leancloud/js-realtime-sdk/pull/606?src=pr&el=h1) Report
> Merging [#606](https://codecov.io/gh/leancloud/js-realtime-sdk/pull/606?src=pr&el=desc) into [master](https://codecov.io/gh/leancloud/js-realtime-sdk/commit/c0a7d1b6ef5c1b1a5a39f51ccc1fa801a9135404?src=pr&el=desc) will **increase** coverage by `0.12%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/leancloud/js-realtime-sdk/pull/606/graphs/tree.svg?width=650&token=HecwtGXAzz&height=150&src=pr)](https://codecov.io/gh/leancloud/js-realtime-sdk/pull/606?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##           master    #606      +/-   ##
=========================================
+ Coverage   96.78%   96.9%   +0.12%     
=========================================
  Files          37      37              
  Lines        1646    1649       +3     
=========================================
+ Hits         1593    1598       +5     
+ Misses         53      51       -2
```


| [Impacted Files](https://codecov.io/gh/leancloud/js-realtime-sdk/pull/606?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/im-client.js](https://codecov.io/gh/leancloud/js-realtime-sdk/pull/606/diff?src=pr&el=tree#diff-c3JjL2ltLWNsaWVudC5qcw==) | `98.21% <100%> (+0.52%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/leancloud/js-realtime-sdk/pull/606?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/leancloud/js-realtime-sdk/pull/606?src=pr&el=footer). Last update [c0a7d1b...6e40593](https://codecov.io/gh/leancloud/js-realtime-sdk/pull/606?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

leeyeh: 这是一个 breaking change。 我改成 next 分支。



Patch:
diff --git a/src/im-client.js b/src/im-client.js
index 7d3adf2..f46f570 100644
--- a/src/im-client.js
+++ b/src/im-client.js
@@ -1333,14 +1333,14 @@ export default class IMClient extends EventEmitter {
    * @param {Object} options 除了下列字段外的其他字段将被视为对话的自定义属性
    * @param {String[]} options.members 对话的初始成员列表，默认包含当前 client
    * @param {String} [options.name] 对话的名字
-   * @param {Boolean} [options.unique=false] 唯一对话，当其为 true 时，如果当前已经有相同成员的对话存在则返回该对话，否则会创建新的对话
+   * @param {Boolean} [options.unique=true] 唯一对话，当其为 true 时，如果当前已经有相同成员的对话存在则返回该对话，否则会创建新的对话
    * @return {Promise.<Conversation>}
    */
   async createConversation({
     members: m,
     name,
     transient,
-    unique,
+    unique = true,
     _tempConv: tempConv,
     _tempConvTTL: tempConvTTL,
     ...properties


Test patch:
diff --git a/test/im-client.js b/test/im-client.js
index 64c6c7a..d8145d5 100644
--- a/test/im-client.js
+++ b/test/im-client.js
@@ -245,6 +245,42 @@ describe('IMClient', () => {
       ).then(conversations => {
         conversations[0].should.be.exactly(conversations[1]);
       }));
+    it('unique by default', () =>
+      series(
+        [0, 0].map(() => () =>
+          client.createConversation({
+            name: 'default unique',
+            members: ['hjiang', 'jfeng'],
+          })
+        )
+      ).then(conversations => {
+        conversations[0].should.be.exactly(conversations[1]);
+      }));
+    it('explicitly not unique', () =>
+      series(
+        [0, 0].map(() => () =>
+          client.createConversation({
+            name: 'default unique',
+            members: ['hjiang', 'jfeng'],
+            unique: false,
+          })
+        )
+      ).then(conversations => {
+        should.notEqual(conversations[0].id, conversations[1].id);
+      }));
+    it('different names', () =>
+      series(
+        ['foo', 'bar'].map(n => () =>
+          client.createConversation({
+            name: n,
+            members: ['hjiang', 'jfeng'],
+            unique: true,
+          })
+        )
+      ).then(conversations => {
+        conversations[0].should.be.exactly(conversations[1]);
+        conversations[0].name.should.be.exactly('bar');
+      }));
     it('transient', () =>
       client
         .createChatRoom({