@@ -27,11 +27,19 @@ describe("MatrixClient", function() {
2727 let store = null ;
2828 const userId = "@alice:localhost" ;
2929 const accessToken = "aseukfgwef" ;
30+ const idServerDomain = "identity.localhost" ; // not a real server
31+ const identityAccessToken = "woop-i-am-a-secret" ;
3032
3133 beforeEach ( function ( ) {
3234 store = new MemoryStore ( ) ;
3335
34- const testClient = new TestClient ( userId , "aliceDevice" , accessToken , undefined , { store } ) ;
36+ const testClient = new TestClient ( userId , "aliceDevice" , accessToken , undefined , {
37+ store,
38+ identityServer : {
39+ getAccessToken : ( ) => Promise . resolve ( identityAccessToken ) ,
40+ } ,
41+ idBaseUrl : `https://${ idServerDomain } ` ,
42+ } ) ;
3543 httpBackend = testClient . httpBackend ;
3644 client = testClient . client ;
3745 } ) ;
@@ -993,7 +1001,7 @@ describe("MatrixClient", function() {
9931001 } ;
9941002
9951003 httpBackend . when ( "GET" , "/_matrix/client/versions" ) . respond ( 200 , {
996- versions : [ "r0.5 .0" ] ,
1004+ versions : [ "r0.6 .0" ] ,
9971005 } ) ;
9981006
9991007 const prom = client . requestRegisterEmailToken ( "bob@email" , "secret" , 1 ) ;
@@ -1008,6 +1016,64 @@ describe("MatrixClient", function() {
10081016 expect ( await prom ) . toStrictEqual ( response ) ;
10091017 } ) ;
10101018 } ) ;
1019+
1020+ describe ( "inviteByThreePid" , ( ) => {
1021+ it ( "should supply an id_access_token" , async ( ) => {
1022+ const targetEmail = "[email protected] " ; 1023+
1024+ httpBackend . when ( "GET" , "/_matrix/client/versions" ) . respond ( 200 , {
1025+ versions : [ "r0.6.0" ] ,
1026+ } ) ;
1027+
1028+ httpBackend . when ( "POST" , "/invite" ) . check ( req => {
1029+ expect ( req . data ) . toStrictEqual ( {
1030+ id_server : idServerDomain ,
1031+ id_access_token : identityAccessToken ,
1032+ medium : "email" ,
1033+ address : targetEmail ,
1034+ } ) ;
1035+ } ) . respond ( 200 , { } ) ;
1036+
1037+ const prom = client . inviteByThreePid ( "!room:example.org" , "email" , targetEmail ) ;
1038+ await httpBackend . flush ( ) ;
1039+ await prom ; // returns empty object, so no validation needed
1040+ } ) ;
1041+ } ) ;
1042+
1043+ describe ( "createRoom" , ( ) => {
1044+ it ( "should populate id_access_token on 3pid invites" , async ( ) => {
1045+ const targetEmail = "[email protected] " ; 1046+ const response = {
1047+ room_id : "!room:localhost" ,
1048+ } ;
1049+ const input = {
1050+ invite_3pid : [ {
1051+ // we intentionally exclude the access token here, so it can be populated for us
1052+ id_server : idServerDomain ,
1053+ medium : "email" ,
1054+ address : targetEmail ,
1055+ } ] ,
1056+ } ;
1057+
1058+ httpBackend . when ( "GET" , "/_matrix/client/versions" ) . respond ( 200 , {
1059+ versions : [ "r0.6.0" ] ,
1060+ } ) ;
1061+
1062+ httpBackend . when ( "POST" , "/createRoom" ) . check ( req => {
1063+ expect ( req . data ) . toMatchObject ( {
1064+ invite_3pid : expect . arrayContaining ( [ {
1065+ ...input . invite_3pid [ 0 ] ,
1066+ id_access_token : identityAccessToken ,
1067+ } ] ) ,
1068+ } ) ;
1069+ expect ( req . data . invite_3pid . length ) . toBe ( 1 ) ;
1070+ } ) . respond ( 200 , response ) ;
1071+
1072+ const prom = client . createRoom ( input ) ;
1073+ await httpBackend . flush ( ) ;
1074+ expect ( await prom ) . toStrictEqual ( response ) ;
1075+ } ) ;
1076+ } ) ;
10111077} ) ;
10121078
10131079function withThreadId ( event , newThreadId ) {
0 commit comments