@@ -4,7 +4,18 @@ import { getPublicIdentity, createIdentity, createProvisionalIdentity } from '@t
44import { expect } from '@tanker/test-utils' ;
55
66import type { AppHelper , TestArgs } from './helpers' ;
7- import { generateUserSession , generateProvisionalUserSession , UserSession , ProvisionalUserSession , encrypt , getPublicIdentities , attachProvisionalIdentities , checkGroup , checkDecrypt , checkDecryptFails } from './helpers' ;
7+ import {
8+ generateUserSession ,
9+ generateProvisionalUserSession ,
10+ UserSession ,
11+ ProvisionalUserSession ,
12+ encrypt ,
13+ getPublicIdentities ,
14+ attachProvisionalIdentities ,
15+ checkGroup ,
16+ checkDecrypt ,
17+ checkDecryptFails ,
18+ } from './helpers' ;
819
920export const generateGroupsTests = ( args : TestArgs ) => {
1021 describe ( 'groups' , ( ) => {
@@ -101,6 +112,13 @@ export const generateGroupsTests = (args: TestArgs) => {
101112 testCases . map ( runTest ) ;
102113 } ) ;
103114
115+ it ( 'create group with an attached provisional identity works' , async ( ) => {
116+ const alice = await UserSession . create ( appHelper ) ;
117+ const provisionalUser = await ProvisionalUserSession . create ( appHelper ) ;
118+ await provisionalUser . attach ( ) ;
119+ await alice . session . createGroup ( [ provisionalUser . spublicIdentity ] ) ;
120+ } ) ;
121+
104122 it ( 'create group with an empty list' , async ( ) => {
105123 const alice = await UserSession . create ( appHelper ) ;
106124 await expect ( alice . session . createGroup ( [ ] ) )
@@ -133,14 +151,6 @@ export const generateGroupsTests = (args: TestArgs) => {
133151 . to . be . rejectedWith ( errors . InvalidArgument , 'Invalid appId for identities' ) ;
134152 } ) ;
135153
136- it ( 'create group with an attached provisional identity' , async ( ) => {
137- const alice = await UserSession . create ( appHelper ) ;
138- const provisionalUser = await ProvisionalUserSession . create ( appHelper ) ;
139- await provisionalUser . attach ( ) ;
140- await expect ( alice . session . createGroup ( [ provisionalUser . spublicIdentity ] ) )
141- . to . be . rejectedWith ( errors . IdentityAlreadyAttached ) ;
142- } ) ;
143-
144154 it ( 'create group with too many users' , async ( ) => {
145155 const alice = await UserSession . create ( appHelper ) ;
146156 const identities : Array < string > = [ ] ;
@@ -477,10 +487,16 @@ export const generateGroupsTests = (args: TestArgs) => {
477487 const alice = await UserSession . create ( appHelper ) ;
478488 const bob = await UserSession . create ( appHelper ) ;
479489 const groupId = await alice . session . createGroup ( [ alice . spublicIdentity ] ) ;
480- await expect ( alice . session . updateGroupMembers ( groupId , { usersToAdd : [ bob . spublicIdentity ] , usersToRemove : [ bob . spublicIdentity ] } ) )
490+ await expect ( alice . session . updateGroupMembers ( groupId , {
491+ usersToAdd : [ bob . spublicIdentity ] ,
492+ usersToRemove : [ bob . spublicIdentity ] ,
493+ } ) )
481494 . to . be . rejectedWith ( errors . InvalidArgument , 'both added to and removed' ) ;
482495 const provisionalUser2 = await ProvisionalUserSession . create ( appHelper ) ;
483- await expect ( alice . session . updateGroupMembers ( groupId , { usersToAdd : [ provisionalUser2 . spublicIdentity ] , usersToRemove : [ provisionalUser2 . spublicIdentity ] } ) )
496+ await expect ( alice . session . updateGroupMembers ( groupId , {
497+ usersToAdd : [ provisionalUser2 . spublicIdentity ] ,
498+ usersToRemove : [ provisionalUser2 . spublicIdentity ] ,
499+ } ) )
484500 . to . be . rejectedWith ( errors . InvalidArgument , 'both added to and removed' ) ;
485501 } ) ;
486502
@@ -493,18 +509,31 @@ export const generateGroupsTests = (args: TestArgs) => {
493509 . to . be . rejectedWith ( errors . InvalidArgument , badGroupId ) ;
494510 } ) ;
495511
496- it ( 'update group members with an attached provisional identity' , async ( ) => {
512+ it ( 'can add group members with an attached provisional identity' , async ( ) => {
497513 const alice = await UserSession . create ( appHelper ) ;
498514 const provisionalUser = await ProvisionalUserSession . create ( appHelper ) ;
499515 const groupId = await alice . session . createGroup (
500516 [ alice . spublicIdentity , provisionalUser . spublicIdentity ] ,
501517 ) ;
502518 await provisionalUser . attach ( ) ;
503519
504- await expect ( alice . session . updateGroupMembers (
520+ await alice . session . updateGroupMembers (
505521 groupId , { usersToAdd : [ provisionalUser . spublicIdentity ] } ,
506- ) )
507- . to . be . rejectedWith ( errors . IdentityAlreadyAttached ) ;
522+ ) ;
523+ } ) ;
524+
525+ it ( 'group members with an attached provisional identity are already automatically removed and cannot be removed again' , async ( ) => {
526+ const alice = await UserSession . create ( appHelper ) ;
527+ const provisionalUser = await ProvisionalUserSession . create ( appHelper ) ;
528+ const groupId = await alice . session . createGroup (
529+ [ alice . spublicIdentity , provisionalUser . spublicIdentity ] ,
530+ ) ;
531+ await alice . session . updateGroupMembers (
532+ groupId , { usersToAdd : [ provisionalUser . spublicIdentity ] } ,
533+ ) ;
534+
535+ await provisionalUser . attach ( ) ;
536+
508537 await expect ( alice . session . updateGroupMembers (
509538 groupId , { usersToRemove : [ provisionalUser . spublicIdentity ] } ,
510539 ) )
@@ -697,12 +726,18 @@ export const generateGroupsTests = (args: TestArgs) => {
697726
698727 const myGroup = await bob . session . createGroup ( [ bob . spublicIdentity ] ) ;
699728
700- const encryptedBuffer = await encrypt ( alice . session , { shareWithSelf : false , shareWithGroups : [ myGroup ] } ) ;
729+ const encryptedBuffer = await encrypt ( alice . session , {
730+ shareWithSelf : false ,
731+ shareWithGroups : [ myGroup ] ,
732+ } ) ;
701733
702734 await checkDecrypt ( [ bob ] , [ encryptedBuffer ] ) ;
703735 await checkDecryptFails ( [ alice ] , [ encryptedBuffer ] ) ;
704736
705- await bob . session . updateGroupMembers ( myGroup , { usersToRemove : [ bob . spublicIdentity ] , usersToAdd : [ alice . spublicIdentity ] } ) ;
737+ await bob . session . updateGroupMembers ( myGroup , {
738+ usersToRemove : [ bob . spublicIdentity ] ,
739+ usersToAdd : [ alice . spublicIdentity ] ,
740+ } ) ;
706741
707742 const bobPhone = await bob . user . makeDevice ( ) ;
708743 const bobCleanSession = await bobPhone . open ( ) ;
0 commit comments