diff --git a/wasm/authenticatedConnection_test.go b/wasm/authenticatedConnection_test.go index b618514b79779d1d59c87ce46727c9ebf692792e..a50eaf12146438699f6da3a85b0f76b6c051026c 100644 --- a/wasm/authenticatedConnection_test.go +++ b/wasm/authenticatedConnection_test.go @@ -35,3 +35,24 @@ func Test_newAuthenticatedConnectionJS(t *testing.T) { } } } + +// Tests that AuthenticatedConnection has all the methods that +// [bindings.AuthenticatedConnection] has. +func Test_AuthenticatedConnectionMethods(t *testing.T) { + authType := reflect.TypeOf(&AuthenticatedConnection{}) + binAuthType := reflect.TypeOf(&bindings.AuthenticatedConnection{}) + + if binAuthType.NumMethod() != authType.NumMethod() { + t.Errorf("WASM AuthenticatedConnection object does not have all "+ + "methods from bindings.\nexpected: %d\nreceived: %d", + binAuthType.NumMethod(), authType.NumMethod()) + } + + for i := 0; i < binAuthType.NumMethod(); i++ { + method := binAuthType.Method(i) + + if _, exists := authType.MethodByName(method.Name); !exists { + t.Errorf("Method %s does not exist.", method.Name) + } + } +} diff --git a/wasm/backup_test.go b/wasm/backup_test.go index 4782f0e1f92c4e4e3bb121a9af95162c129c80bb..8946fc6aefaf2fe15a7fc452e1559194ee41502c 100644 --- a/wasm/backup_test.go +++ b/wasm/backup_test.go @@ -32,3 +32,23 @@ func Test_newBackupJS(t *testing.T) { } } } + +// Tests that Backup has all the methods that [bindings.Backup] has. +func Test_BackupMethods(t *testing.T) { + backupType := reflect.TypeOf(&Backup{}) + binBackupType := reflect.TypeOf(&bindings.Backup{}) + + if binBackupType.NumMethod() != backupType.NumMethod() { + t.Errorf("WASM Backup object does not have all methods from bindings."+ + "\nexpected: %d\nreceived: %d", + binBackupType.NumMethod(), backupType.NumMethod()) + } + + for i := 0; i < binBackupType.NumMethod(); i++ { + method := binBackupType.Method(i) + + if _, exists := backupType.MethodByName(method.Name); !exists { + t.Errorf("Method %s does not exist.", method.Name) + } + } +} diff --git a/wasm/broadcast_test.go b/wasm/broadcast_test.go index 4dc4688355f65e2044c4c3d758375c73863b6214..3541c5c09084b29e37c7ef37328969dc27b03d1b 100644 --- a/wasm/broadcast_test.go +++ b/wasm/broadcast_test.go @@ -34,3 +34,23 @@ func Test_newChannelJS(t *testing.T) { } } } + +// Tests that Channel has all the methods that [bindings.Channel] has. +func Test_ChannelMethods(t *testing.T) { + chanType := reflect.TypeOf(&Channel{}) + binChanType := reflect.TypeOf(&bindings.Channel{}) + + if binChanType.NumMethod() != chanType.NumMethod() { + t.Errorf("WASM Channel object does not have all methods from bindings."+ + "\nexpected: %d\nreceived: %d", + binChanType.NumMethod(), chanType.NumMethod()) + } + + for i := 0; i < binChanType.NumMethod(); i++ { + method := binChanType.Method(i) + + if _, exists := chanType.MethodByName(method.Name); !exists { + t.Errorf("Method %s does not exist.", method.Name) + } + } +} diff --git a/wasm/cmix_test.go b/wasm/cmix_test.go index 316b1508c184ad99832119ddcfd53c25e10395c0..703440b4bfa2a0183583407c9fa052a6d47bc09c 100644 --- a/wasm/cmix_test.go +++ b/wasm/cmix_test.go @@ -35,3 +35,23 @@ func Test_newCmixJS(t *testing.T) { } } } + +// Tests that Cmix has all the methods that [bindings.Cmix] has. +func Test_CmixMethods(t *testing.T) { + cmixType := reflect.TypeOf(&Cmix{}) + binCmixType := reflect.TypeOf(&bindings.Cmix{}) + + if binCmixType.NumMethod() != cmixType.NumMethod() { + t.Errorf("WASM Cmix object does not have all methods from bindings."+ + "\nexpected: %d\nreceived: %d", + binCmixType.NumMethod(), cmixType.NumMethod()) + } + + for i := 0; i < binCmixType.NumMethod(); i++ { + method := binCmixType.Method(i) + + if _, exists := cmixType.MethodByName(method.Name); !exists { + t.Errorf("Method %s does not exist.", method.Name) + } + } +} diff --git a/wasm/connect_test.go b/wasm/connect_test.go index f9cba409167499bcc33365eb3a730a3c0eaea138..c2acb98aa8b4c11ee216759ff2227a6b79db5816 100644 --- a/wasm/connect_test.go +++ b/wasm/connect_test.go @@ -32,3 +32,23 @@ func Test_newConnectJS(t *testing.T) { } } } + +// Tests that Connection has all the methods that [bindings.Connection] has. +func Test_ConnectionMethods(t *testing.T) { + connType := reflect.TypeOf(&Connection{}) + binConnType := reflect.TypeOf(&bindings.Connection{}) + + if binConnType.NumMethod() != connType.NumMethod() { + t.Errorf("WASM Connection object does not have all methods from "+ + "bindings.\nexpected: %d\nreceived: %d", + binConnType.NumMethod(), connType.NumMethod()) + } + + for i := 0; i < binConnType.NumMethod(); i++ { + method := binConnType.Method(i) + + if _, exists := connType.MethodByName(method.Name); !exists { + t.Errorf("Method %s does not exist.", method.Name) + } + } +} diff --git a/wasm/e2e_test.go b/wasm/e2e_test.go index 107086be968767b5b5ce74541e4a2264e43a0e3f..d4b55d21320a42ff5f85e77c289cb91a705f6896 100644 --- a/wasm/e2e_test.go +++ b/wasm/e2e_test.go @@ -34,3 +34,23 @@ func Test_newE2eJS(t *testing.T) { } } } + +// Tests that E2e has all the methods that [bindings.E2e] has. +func Test_E2eMethods(t *testing.T) { + e2eType := reflect.TypeOf(&E2e{}) + binE2eType := reflect.TypeOf(&bindings.E2e{}) + + if binE2eType.NumMethod() != e2eType.NumMethod() { + t.Errorf("WASM E2e object does not have all methods from bindings."+ + "\nexpected: %d\nreceived: %d", + binE2eType.NumMethod(), e2eType.NumMethod()) + } + + for i := 0; i < binE2eType.NumMethod(); i++ { + method := binE2eType.Method(i) + + if _, exists := e2eType.MethodByName(method.Name); !exists { + t.Errorf("Method %s does not exist.", method.Name) + } + } +} diff --git a/wasm/fileTransfer_test.go b/wasm/fileTransfer_test.go index bbdf8d98c05e4ecd2dcafd6df61b10cbd1317bed..b339903f19465f9bc8a5f27f68d589884bb3f812 100644 --- a/wasm/fileTransfer_test.go +++ b/wasm/fileTransfer_test.go @@ -33,6 +33,26 @@ func Test_newFileTransferJS(t *testing.T) { } } +// Tests that FileTransfer has all the methods that [bindings.FileTransfer] has. +func Test_FileTransferMethods(t *testing.T) { + ftType := reflect.TypeOf(&FileTransfer{}) + binFtType := reflect.TypeOf(&bindings.FileTransfer{}) + + if binFtType.NumMethod() != ftType.NumMethod() { + t.Errorf("WASM FileTransfer object does not have all methods from "+ + "bindings.\nexpected: %d\nreceived: %d", + binFtType.NumMethod(), ftType.NumMethod()) + } + + for i := 0; i < binFtType.NumMethod(); i++ { + method := binFtType.Method(i) + + if _, exists := ftType.MethodByName(method.Name); !exists { + t.Errorf("Method %s does not exist.", method.Name) + } + } +} + // Tests that the map representing FilePartTracker returned by // newFilePartTrackerJS contains all of the methods on FilePartTracker. func Test_newFilePartTrackerJS(t *testing.T) { @@ -52,3 +72,24 @@ func Test_newFilePartTrackerJS(t *testing.T) { } } } + +// Tests that FilePartTracker has all the methods that +// [bindings.FilePartTracker] has. +func Test_FilePartTrackerMethods(t *testing.T) { + fptType := reflect.TypeOf(&FilePartTracker{}) + binFptType := reflect.TypeOf(&bindings.FilePartTracker{}) + + if binFptType.NumMethod() != fptType.NumMethod() { + t.Errorf("WASM FilePartTracker object does not have all methods from "+ + "bindings.\nexpected: %d\nreceived: %d", + binFptType.NumMethod(), fptType.NumMethod()) + } + + for i := 0; i < binFptType.NumMethod(); i++ { + method := binFptType.Method(i) + + if _, exists := fptType.MethodByName(method.Name); !exists { + t.Errorf("Method %s does not exist.", method.Name) + } + } +} diff --git a/wasm/follow.go b/wasm/follow.go index 8da6a4d72b192590b0d8e84b861d1804b785940a..a21912fa8fe33355dd0a071eea009ca8dca50c22 100644 --- a/wasm/follow.go +++ b/wasm/follow.go @@ -191,8 +191,32 @@ func (ce *clientError) Report(source, message, trace string) { // // Parameters: // - args[0] - Javascript object that has functions that implement the -// [bindings.ClientError] interface +// [bindings.ClientError] interface. func (c *Cmix) RegisterClientErrorCallback(_ js.Value, args []js.Value) interface{} { c.api.RegisterClientErrorCallback(&clientError{utils.WrapCB(args[0], "Report")}) return nil } + +// trackServicesCallback adheres to the [bindings.TrackServicesCallback] +// interface. +type trackServicesCallback struct { + callback func(args ...interface{}) js.Value +} + +func (tsc *trackServicesCallback) Callback(marshalData []byte, err error) { + tsc.callback(utils.CopyBytesToJS(marshalData), utils.JsTrace(err)) +} + +// TrackServices will return, via a callback, the list of services that the +// backend keeps track of, which is formally referred to as a +// [message.ServiceList]. This may be passed into other bindings call that may +// need context on the available services for this client. +// +// Parameters: +// - args[0] - Javascript object that has functions that implement the +// [bindings.TrackServicesCallback] interface. +func (c *Cmix) TrackServices(_ js.Value, args []js.Value) interface{} { + c.api.TrackServices( + &trackServicesCallback{utils.WrapCB(args[0], "Callback")}) + return nil +} diff --git a/wasm/group_test.go b/wasm/group_test.go index cc64e5f8396c8bf7490e79f172a9d204eb705ba7..1350fc4a34f6f0d4fb826e06ef61e4fc2e1246aa 100644 --- a/wasm/group_test.go +++ b/wasm/group_test.go @@ -35,22 +35,62 @@ func Test_newGroupChatJS(t *testing.T) { } } +// Tests that GroupChat has all the methods that [bindings.GroupChat] has. +func Test_GroupChatMethods(t *testing.T) { + gcType := reflect.TypeOf(&GroupChat{}) + binGcType := reflect.TypeOf(&bindings.GroupChat{}) + + if binGcType.NumMethod() != gcType.NumMethod() { + t.Errorf("WASM GroupChat object does not have all methods from "+ + "bindings.\nexpected: %d\nreceived: %d", + binGcType.NumMethod(), gcType.NumMethod()) + } + + for i := 0; i < binGcType.NumMethod(); i++ { + method := binGcType.Method(i) + + if _, exists := gcType.MethodByName(method.Name); !exists { + t.Errorf("Method %s does not exist.", method.Name) + } + } +} + // Tests that the map representing Group returned by newGroupJS contains all of // the methods on Group. func Test_newGroupJS(t *testing.T) { - gType := reflect.TypeOf(&Group{}) + grpType := reflect.TypeOf(&Group{}) g := newGroupJS(&bindings.Group{}) - if len(g) != gType.NumMethod() { + if len(g) != grpType.NumMethod() { t.Errorf("Group JS object does not have all methods."+ - "\nexpected: %d\nreceived: %d", gType.NumMethod(), len(g)) + "\nexpected: %d\nreceived: %d", grpType.NumMethod(), len(g)) } - for i := 0; i < gType.NumMethod(); i++ { - method := gType.Method(i) + for i := 0; i < grpType.NumMethod(); i++ { + method := grpType.Method(i) if _, exists := g[method.Name]; !exists { t.Errorf("Method %s does not exist.", method.Name) } } } + +// Tests that Group has all the methods that [bindings.Group] has. +func Test_GroupMethods(t *testing.T) { + grpType := reflect.TypeOf(&Group{}) + binGrpType := reflect.TypeOf(&bindings.Group{}) + + if binGrpType.NumMethod() != grpType.NumMethod() { + t.Errorf("WASM Group object does not have all methods from bindings."+ + "\nexpected: %d\nreceived: %d", + binGrpType.NumMethod(), grpType.NumMethod()) + } + + for i := 0; i < binGrpType.NumMethod(); i++ { + method := binGrpType.Method(i) + + if _, exists := grpType.MethodByName(method.Name); !exists { + t.Errorf("Method %s does not exist.", method.Name) + } + } +} diff --git a/wasm/single_test.go b/wasm/single_test.go index 48017c5d3a5d5f6a0459d33cbdbd864be5e615b2..d1276075615ae01015e22ddef0b1063c11bb6ddc 100644 --- a/wasm/single_test.go +++ b/wasm/single_test.go @@ -10,6 +10,7 @@ package wasm import ( + "gitlab.com/elixxir/client/bindings" "reflect" "testing" ) @@ -34,6 +35,26 @@ func Test_newStopperJS(t *testing.T) { } } +// Tests that Stopper has all the methods that [bindings.Stopper] has. +func Test_StopperMethods(t *testing.T) { + stopperType := reflect.TypeOf(&Stopper{}) + binStopperType := reflect.TypeOf(bindings.Stopper(&stopper{})) + + if binStopperType.NumMethod() != stopperType.NumMethod() { + t.Errorf("WASM Stopper object does not have all methods from bindings."+ + "\nexpected: %d\nreceived: %d", + binStopperType.NumMethod(), stopperType.NumMethod()) + } + + for i := 0; i < binStopperType.NumMethod(); i++ { + method := binStopperType.Method(i) + + if _, exists := stopperType.MethodByName(method.Name); !exists { + t.Errorf("Method %s does not exist.", method.Name) + } + } +} + type stopper struct{} func (s *stopper) Stop() {} diff --git a/wasm/ud_test.go b/wasm/ud_test.go index 37761fa9ef38e233bc675f57a4004be2c68d1ea5..40ae06bc11a71baf48072834eb8917c426d96593 100644 --- a/wasm/ud_test.go +++ b/wasm/ud_test.go @@ -34,3 +34,24 @@ func Test_newUserDiscoveryJS(t *testing.T) { } } } + +// Tests that UserDiscovery has all the methods that [bindings.UserDiscovery] +// has. +func Test_UserDiscoveryMethods(t *testing.T) { + udType := reflect.TypeOf(&UserDiscovery{}) + binUdType := reflect.TypeOf(&bindings.UserDiscovery{}) + + if binUdType.NumMethod() != udType.NumMethod() { + t.Errorf("WASM UserDiscovery object does not have all methods from "+ + "bindings.\nexpected: %d\nreceived: %d", + binUdType.NumMethod(), udType.NumMethod()) + } + + for i := 0; i < binUdType.NumMethod(); i++ { + method := binUdType.Method(i) + + if _, exists := udType.MethodByName(method.Name); !exists { + t.Errorf("Method %s does not exist.", method.Name) + } + } +}