From 1d41c3fac35936fea7a8dc5604026e409ec03272 Mon Sep 17 00:00:00 2001 From: Tim Boeckmann Date: Mon, 6 Jul 2020 20:00:22 +0100 Subject: [PATCH 1/8] tweak tests --- src/karma.conf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/karma.conf.js b/src/karma.conf.js index 08ac0d7..49f67d5 100644 --- a/src/karma.conf.js +++ b/src/karma.conf.js @@ -42,7 +42,7 @@ module.exports = function (config) { specReporter: { maxLogLines: 5, // limit number of lines logged per test suppressErrorSummary: false, // do not print error summary - suppressPassed: false, // do not print information about passed tests + suppressPassed: true, // do not print information about passed tests suppressFailed: false, // do not print information about failed tests suppressSkipped: true, // do not print information about skipped tests showSpecTiming: false // print the time elapsed for each spec From 92e44db6effbe61fd31c710d4ec845f2ae40ef00 Mon Sep 17 00:00:00 2001 From: Tim Boeckmann Date: Mon, 6 Jul 2020 20:00:46 +0100 Subject: [PATCH 2/8] add tests and helpers --- .../inbox-compose.component.spec.ts | 16 ++++++++++++++++ src/app/models/mail.ts | 1 + .../mailchain/messages/send.service.spec.ts | 9 +++++++++ .../test/test-helpers/mailchain-test.service.ts | 15 +++++++++++++++ 4 files changed, 41 insertions(+) diff --git a/src/app/inbox/inbox-compose/inbox-compose.component.spec.ts b/src/app/inbox/inbox-compose/inbox-compose.component.spec.ts index 0fbba59..45ed18a 100644 --- a/src/app/inbox/inbox-compose/inbox-compose.component.spec.ts +++ b/src/app/inbox/inbox-compose/inbox-compose.component.spec.ts @@ -147,8 +147,24 @@ describe('InboxComposeComponent', () => { await component.ngOnInit(); expect(component.model.body).toBe('') }) + + describe('handling the envelope', () => { + it('should initialize an envelope in the "envelope" field using an available envelop', async () => { + await component.ngOnInit(); + fixture.detectChanges() + expect(component.model.envelope).toBe('0x01') + }) + + it('should populate the envelope_type dropdown if there are multiple envelopes available', async () => { + await component.ngOnInit(); + expect(component.model.envelope).toBe('') + }) + + }) + }); + describe('when composing a plaintext reply', () => { beforeEach(() => { component.currentMessage = mailchainTestService.inboundMessage(); diff --git a/src/app/models/mail.ts b/src/app/models/mail.ts index 4a3de5e..db1b866 100644 --- a/src/app/models/mail.ts +++ b/src/app/models/mail.ts @@ -4,4 +4,5 @@ export class Mail { public subject: string = ""; public body: string = ""; public publicKey: string = ""; + public envelope: string = ""; } \ No newline at end of file diff --git a/src/app/services/mailchain/messages/send.service.spec.ts b/src/app/services/mailchain/messages/send.service.spec.ts index 6ffc93d..045e89a 100644 --- a/src/app/services/mailchain/messages/send.service.spec.ts +++ b/src/app/services/mailchain/messages/send.service.spec.ts @@ -158,6 +158,15 @@ describe('SendService', () => { // outboundMailObject["encryption-method-name"] = "" }) + it('should specify `envelope` in the outbound mail', () => { + let outboundMailObject = mailchainTestService.outboundMailObject() + expect(outboundMailObject["envelope"]).not.toBeUndefined() + }) + + it('should error on send if `envelope` is empty in the outbound mail', () => { + // TODO add test for: should error on send if envelope is empty in the outbound mail + }) + it('should specify content-type as "text/plain; charset=\"UTF-8\"" by default in the outbound mail', () => { let outboundMailObject = mailchainTestService.outboundMailObject() expect(outboundMailObject["content-type"]).toBe("text/plain; charset=\"UTF-8\"") diff --git a/src/app/test/test-helpers/mailchain-test.service.ts b/src/app/test/test-helpers/mailchain-test.service.ts index 1ea6348..0f9704f 100644 --- a/src/app/test/test-helpers/mailchain-test.service.ts +++ b/src/app/test/test-helpers/mailchain-test.service.ts @@ -300,5 +300,20 @@ export class MailchainTestService { } } + public envelopeTypeMli(): any { + return [{ "type": "0x01", "description": "Private Message Stored with MLI" }] + } + + public envelopeTypeIpfs(): any { + return [{ "type": "0x02", "description": "Private Message Stored on IPFS" }] + } + + public envelopeTypesMultiple(): any { + return [ + { "type": "0x01", "description": "Private Message Stored with MLI" }, + { "type": "0x02", "description": "Private Message Stored on IPFS" } + ] + } + } From beec6461cba774e5790114fd5bbfc8ee7ec800a9 Mon Sep 17 00:00:00 2001 From: Tim Boeckmann Date: Mon, 6 Jul 2020 20:00:58 +0100 Subject: [PATCH 3/8] add envelopeService --- .../envelope/envelope.service.spec.ts | 65 +++++++++++++++++++ .../mailchain/envelope/envelope.service.ts | 47 ++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 src/app/services/mailchain/envelope/envelope.service.spec.ts create mode 100644 src/app/services/mailchain/envelope/envelope.service.ts diff --git a/src/app/services/mailchain/envelope/envelope.service.spec.ts b/src/app/services/mailchain/envelope/envelope.service.spec.ts new file mode 100644 index 0000000..44d1c8f --- /dev/null +++ b/src/app/services/mailchain/envelope/envelope.service.spec.ts @@ -0,0 +1,65 @@ +import { TestBed } from '@angular/core/testing'; +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; + +import { EnvelopeService } from './envelope.service'; + +import { MailchainTestService } from 'src/app/test/test-helpers/mailchain-test.service'; +import { HttpHelpersService } from '../../helpers/http-helpers/http-helpers.service'; + + +describe('EnvelopeService', () => { + + let envelopeService: EnvelopeService; + let httpTestingController: HttpTestingController; + let mailchainTestService: MailchainTestService + let serverResponse + let expectedAddresses + + const desiredUrl = `http://127.0.0.1:8080/api/envelope` + + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [ + EnvelopeService, + HttpHelpersService, + ], + imports: [HttpClientTestingModule] + }); + + envelopeService = TestBed.get(EnvelopeService); + mailchainTestService = TestBed.get(MailchainTestService); + httpTestingController = TestBed.get(HttpTestingController); + + serverResponse = mailchainTestService.envelopeTypesMultiple() + }); + + afterEach(() => { + httpTestingController.verify(); + }); + + it('should be created', () => { + const service: EnvelopeService = TestBed.get(EnvelopeService); + expect(service).toBeTruthy(); + }); + + + describe('initUrl', () => { + it('should initialize the url', () => { + expect(envelopeService['url']).toEqual('http://127.0.0.1:8080/api') + }); + }) + + it('should get an array of envelope types with their description', () => { + envelopeService.getEnvelope().then(res => { + console.log(res); + + expect(res).toEqual(serverResponse) + }); + + // handle open connections + const req = httpTestingController.expectOne(desiredUrl); + expect(req.request.method).toBe("GET"); + req.flush(serverResponse); + }); + +}); diff --git a/src/app/services/mailchain/envelope/envelope.service.ts b/src/app/services/mailchain/envelope/envelope.service.ts new file mode 100644 index 0000000..e45e152 --- /dev/null +++ b/src/app/services/mailchain/envelope/envelope.service.ts @@ -0,0 +1,47 @@ +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { LocalStorageServerService } from '../../helpers/local-storage-server/local-storage-server.service'; +import { HttpHelpersService } from '../../helpers/http-helpers/http-helpers.service'; + +@Injectable({ + providedIn: 'root' +}) +export class EnvelopeService { + + private url: string + private protocol: string + private network: string + + constructor( + private http: HttpClient, + private httpHelpersService: HttpHelpersService, + private localStorageServerService: LocalStorageServerService, + ) { + this.initUrl() + } + + /** + * Initialize URL from local storage + */ + initUrl() { + this.url = `${this.localStorageServerService.getCurrentServerDetails()}/api` + } + + /** + * Get and return the available envelope(s) + */ + async getEnvelope() { + + var envelopes = [] + let res = await this.http.get( + this.url + `/envelope` + // TODO handle failure + ).toPromise(); + res["body"]["envelope"].forEach(envelope => { + envelopes.push(JSON.parse(envelope)) + console.log(envelopes); + + }); + return envelopes + } +} From a1f24664d28d5d10ad975ade2af715404306bb38 Mon Sep 17 00:00:00 2001 From: Tim Boeckmann Date: Mon, 6 Jul 2020 23:43:59 +0100 Subject: [PATCH 4/8] add tests handle envelopes --- .../inbox-compose.component.html | 19 +++++++++++++- .../inbox-compose/inbox-compose.component.ts | 26 ++++++++++++++++++- .../envelope/envelope.service.spec.ts | 2 -- .../mailchain/envelope/envelope.service.ts | 12 +-------- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/app/inbox/inbox-compose/inbox-compose.component.html b/src/app/inbox/inbox-compose/inbox-compose.component.html index 898e659..5174854 100644 --- a/src/app/inbox/inbox-compose/inbox-compose.component.html +++ b/src/app/inbox/inbox-compose/inbox-compose.component.html @@ -31,7 +31,6 @@

Compose New

-
@@ -65,6 +64,24 @@

Compose New

+ + +
+ +
+
+ +
+
+
+ + +
diff --git a/src/app/inbox/inbox-compose/inbox-compose.component.ts b/src/app/inbox/inbox-compose/inbox-compose.component.ts index 266e239..346f506 100644 --- a/src/app/inbox/inbox-compose/inbox-compose.component.ts +++ b/src/app/inbox/inbox-compose/inbox-compose.component.ts @@ -5,6 +5,7 @@ import { MailchainService } from 'src/app/services/mailchain/mailchain.service'; import { SendService } from 'src/app/services/mailchain/messages/send.service'; import { PublicKeyService } from 'src/app/services/mailchain/public-key/public-key.service'; import { AddressesService } from 'src/app/services/mailchain/addresses/addresses.service'; +import { EnvelopeService } from 'src/app/services/mailchain/envelope/envelope.service'; import { NameserviceService } from 'src/app/services/mailchain/nameservice/nameservice.service'; import { Subject, of, Observable } from 'rxjs'; @@ -32,6 +33,8 @@ export class InboxComposeComponent implements OnInit { public model = new Mail() public fromAddresses: Array = [] + public envelopes: Array = [] + public sendMessagesDisabled: boolean = false; private subscription public currentRecipientValue @@ -56,6 +59,7 @@ export class InboxComposeComponent implements OnInit { private sendService: SendService, private publicKeyService: PublicKeyService, private addressesService: AddressesService, + private envelopeService: EnvelopeService, private nameserviceService: NameserviceService, private modalService: BsModalService, ) { } @@ -68,6 +72,7 @@ export class InboxComposeComponent implements OnInit { this.model.from = "" this.model.subject = "" this.model.body = "" + this.model.envelope = "" } /** @@ -97,12 +102,19 @@ export class InboxComposeComponent implements OnInit { } /** - * Sets the available from addresses + * Sets the available 'from' addresses */ private async setFromAddressList() { this.fromAddresses = await this.addressesService.getAddresses(); } + /** + * Sets the available envelopes + */ + private async setEnvelopeList() { + this.envelopes = await this.envelopeService.getEnvelope(); + } + /** * Returns the identicon for the an address * @param address the address @@ -271,6 +283,16 @@ export class InboxComposeComponent implements OnInit { } } + /** + * Sets the envelope in the `envelope` dropdown + * By default takes the first value returned from the /envelop endpoint + */ + private setFirstEnvelopeInEnvelopeDropdown() { + if (this.envelopes != undefined) { + this.model.envelope = this.envelopes[0]["type"] + } + } + /** * Initialise the message. * If it's a new message, fields will be blank. @@ -279,10 +301,12 @@ export class InboxComposeComponent implements OnInit { */ async ngOnInit(): Promise { await this.setFromAddressList() + await this.setEnvelopeList() this.setContentTypeForView() this.initMail() this.initEditor() this.setCurrentAccountInFromAddressDropdown() + this.setFirstEnvelopeInEnvelopeDropdown() this.handleReplyFields() this.setupRecipientAddressLookupSubscription() } diff --git a/src/app/services/mailchain/envelope/envelope.service.spec.ts b/src/app/services/mailchain/envelope/envelope.service.spec.ts index 44d1c8f..410d816 100644 --- a/src/app/services/mailchain/envelope/envelope.service.spec.ts +++ b/src/app/services/mailchain/envelope/envelope.service.spec.ts @@ -51,8 +51,6 @@ describe('EnvelopeService', () => { it('should get an array of envelope types with their description', () => { envelopeService.getEnvelope().then(res => { - console.log(res); - expect(res).toEqual(serverResponse) }); diff --git a/src/app/services/mailchain/envelope/envelope.service.ts b/src/app/services/mailchain/envelope/envelope.service.ts index e45e152..125a449 100644 --- a/src/app/services/mailchain/envelope/envelope.service.ts +++ b/src/app/services/mailchain/envelope/envelope.service.ts @@ -1,7 +1,6 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { LocalStorageServerService } from '../../helpers/local-storage-server/local-storage-server.service'; -import { HttpHelpersService } from '../../helpers/http-helpers/http-helpers.service'; @Injectable({ providedIn: 'root' @@ -9,12 +8,9 @@ import { HttpHelpersService } from '../../helpers/http-helpers/http-helpers.serv export class EnvelopeService { private url: string - private protocol: string - private network: string constructor( private http: HttpClient, - private httpHelpersService: HttpHelpersService, private localStorageServerService: LocalStorageServerService, ) { this.initUrl() @@ -32,16 +28,10 @@ export class EnvelopeService { */ async getEnvelope() { - var envelopes = [] - let res = await this.http.get( + let envelopes = await this.http.get( this.url + `/envelope` // TODO handle failure ).toPromise(); - res["body"]["envelope"].forEach(envelope => { - envelopes.push(JSON.parse(envelope)) - console.log(envelopes); - - }); return envelopes } } From de9b71f76919246247811c297369e4daa03b58a3 Mon Sep 17 00:00:00 2001 From: Tim Boeckmann Date: Mon, 6 Jul 2020 23:53:08 +0100 Subject: [PATCH 5/8] clean up tests --- .../inbox-compose.component.spec.ts | 24 +++++++++- .../connectivity/connectivity.service.spec.ts | 44 +++++++++---------- .../mailchain/messages/send.service.spec.ts | 10 ++--- 3 files changed, 49 insertions(+), 29 deletions(-) diff --git a/src/app/inbox/inbox-compose/inbox-compose.component.spec.ts b/src/app/inbox/inbox-compose/inbox-compose.component.spec.ts index 45ed18a..b15b571 100644 --- a/src/app/inbox/inbox-compose/inbox-compose.component.spec.ts +++ b/src/app/inbox/inbox-compose/inbox-compose.component.spec.ts @@ -19,6 +19,7 @@ import { ModalModule, BsModalRef } from 'ngx-bootstrap/modal'; import { ModalConnectivityErrorComponent } from '../../modals/modal-connectivity-error/modal-connectivity-error.component'; import { NgModule } from '@angular/core'; import { CKEditorModule, CKEditorComponent } from '@ckeditor/ckeditor5-angular'; +import { EnvelopeService } from 'src/app/services/mailchain/envelope/envelope.service'; // Workaround: @@ -43,12 +44,19 @@ describe('InboxComposeComponent', () => { const currentAccount2 = '0x0123456789abcdef0123456789abcdef01234567'; const ensName = 'mailchain.eth'; const addresses = [currentAccount, currentAccount2]; + let envelopes: Array class AddressesServiceStub { getAddresses() { return addresses } } + + class EnvelopeServiceStub { + getEnvelope() { + return envelopes // set envelope in test + } + } class PublicKeyServiceStub { getPublicKeyFromAddress(publicAddress, network) { return of(['1234567890']) @@ -77,6 +85,7 @@ describe('InboxComposeComponent', () => { HttpHelpersService, MailchainService, { provide: AddressesService, useClass: AddressesServiceStub }, + { provide: EnvelopeService, useClass: EnvelopeServiceStub }, { provide: PublicKeyService, useClass: PublicKeyServiceStub }, { provide: SendService, useClass: SendServiceStub }, { provide: NameserviceService, useClass: NameserviceServiceStub }, @@ -150,14 +159,25 @@ describe('InboxComposeComponent', () => { describe('handling the envelope', () => { it('should initialize an envelope in the "envelope" field using an available envelop', async () => { + envelopes = mailchainTestService.envelopeTypeMli() + expect(component.model.envelope).toBe('') await component.ngOnInit(); fixture.detectChanges() expect(component.model.envelope).toBe('0x01') }) - it('should populate the envelope_type dropdown if there are multiple envelopes available', async () => { + it('should initialize an envelope in the "envelope" field using an available envelop', async () => { + envelopes = mailchainTestService.envelopeTypeIpfs() await component.ngOnInit(); - expect(component.model.envelope).toBe('') + fixture.detectChanges() + expect(component.model.envelope).toBe('0x02') + }) + + it('should populate the envelope_type dropdown with the first value if there are multiple envelopes available', async () => { + envelopes = mailchainTestService.envelopeTypesMultiple() + await component.ngOnInit(); + fixture.detectChanges() + expect(component.model.envelope).toBe('0x01') }) }) diff --git a/src/app/services/mailchain/connectivity/connectivity.service.spec.ts b/src/app/services/mailchain/connectivity/connectivity.service.spec.ts index df20cfc..ab54c30 100644 --- a/src/app/services/mailchain/connectivity/connectivity.service.spec.ts +++ b/src/app/services/mailchain/connectivity/connectivity.service.spec.ts @@ -41,14 +41,14 @@ describe('ConnectivityService', () => { }); describe('getVersionStatus', () => { - it('should handle dirty semver', () => { + it('should handle dirty semver', async () => { let resReleaseObs = of({ "tag_name": "v0.0.1" }); let clientReleaseObs = of({ "version": "0.0.1" }); spyOn(http, 'get').and.returnValue(resReleaseObs); spyOn(versionService, 'getVersion').and.returnValue(clientReleaseObs); - connectivityService.getVersionStatus() + await connectivityService.getVersionStatus() .then(res => { expect(res["client-version"]).toEqual("0.0.1") expect(res["release-version"]).toEqual("0.0.1") @@ -58,14 +58,14 @@ describe('ConnectivityService', () => { }); - it('should return status unknown if releaseVersion is not present', () => { + it('should return status unknown if releaseVersion is not present', async () => { let resReleaseObs = of({ "some_tag": "some_data" }); let clientReleaseObs = of({ "version": "0.0.1" }); spyOn(http, 'get').and.returnValue(resReleaseObs); spyOn(versionService, 'getVersion').and.returnValue(clientReleaseObs); - connectivityService.getVersionStatus() + await connectivityService.getVersionStatus() .then(res => { expect(res["client-version"]).toEqual("0.0.1") expect(res["release-version"]).toEqual("unknown") @@ -73,14 +73,14 @@ describe('ConnectivityService', () => { expect(res["errors"]).toEqual(0) }) }); - it('should return status unknown if clientVersion is not present', () => { + it('should return status unknown if clientVersion is not present', async () => { let resReleaseObs = of({ "tag_name": "v0.0.1" }); let clientReleaseObs = of({ "some_val": "some_data" }); spyOn(http, 'get').and.returnValue(resReleaseObs); spyOn(versionService, 'getVersion').and.returnValue(clientReleaseObs); - connectivityService.getVersionStatus() + await connectivityService.getVersionStatus() .then(res => { expect(res["client-version"]).toEqual("unknown") expect(res["release-version"]).toEqual("0.0.1") @@ -89,14 +89,14 @@ describe('ConnectivityService', () => { }) }); - it('should return status unknown if releaseVersion is not valid', () => { + it('should return status unknown if releaseVersion is not valid', async () => { let resReleaseObs = of({ "tag_name": "dev" }); let clientReleaseObs = of({ "version": "0.0.1" }); spyOn(http, 'get').and.returnValue(resReleaseObs); spyOn(versionService, 'getVersion').and.returnValue(clientReleaseObs); - connectivityService.getVersionStatus() + await connectivityService.getVersionStatus() .then(res => { expect(res["client-version"]).toEqual("0.0.1") expect(res["release-version"]).toEqual("unknown") @@ -104,14 +104,14 @@ describe('ConnectivityService', () => { expect(res["errors"]).toEqual(0) }) }); - it('should return status unknown if clientVersion is not valid', () => { + it('should return status unknown if clientVersion is not valid', async () => { let resReleaseObs = of({ "tag_name": "v0.0.1" }); let clientReleaseObs = of({ "version": "dev" }); spyOn(http, 'get').and.returnValue(resReleaseObs); spyOn(versionService, 'getVersion').and.returnValue(clientReleaseObs); - connectivityService.getVersionStatus() + await connectivityService.getVersionStatus() .then(res => { expect(res["client-version"]).toEqual("unknown") expect(res["release-version"]).toEqual("0.0.1") @@ -120,14 +120,14 @@ describe('ConnectivityService', () => { }) }); - it('should return status ok if releaseVersion is the same as clientVersion', () => { + it('should return status ok if releaseVersion is the same as clientVersion', async () => { let resReleaseObs = of({ "tag_name": "0.0.1" }); let clientReleaseObs = of({ "version": "0.0.1" }); spyOn(http, 'get').and.returnValue(resReleaseObs); spyOn(versionService, 'getVersion').and.returnValue(clientReleaseObs); - connectivityService.getVersionStatus() + await connectivityService.getVersionStatus() .then(res => { expect(res["client-version"]).toEqual("0.0.1") expect(res["release-version"]).toEqual("0.0.1") @@ -136,14 +136,14 @@ describe('ConnectivityService', () => { }) }); - it('should return status outdated if clientVersion is less than releaseVersion', () => { + it('should return status outdated if clientVersion is less than releaseVersion', async () => { let resReleaseObs = of({ "tag_name": "v0.0.3" }); let clientReleaseObs = of({ "version": "0.0.1" }); spyOn(http, 'get').and.returnValue(resReleaseObs); spyOn(versionService, 'getVersion').and.returnValue(clientReleaseObs); - connectivityService.getVersionStatus() + await connectivityService.getVersionStatus() .then(res => { expect(res["client-version"]).toEqual("0.0.1") expect(res["release-version"]).toEqual("0.0.3") @@ -152,14 +152,14 @@ describe('ConnectivityService', () => { }) }); - it('should return status unknown if clientVersion is greater than releaseVersion', () => { + it('should return status unknown if clientVersion is greater than releaseVersion', async () => { let resReleaseObs = of({ "tag_name": "0.0.1" }); let clientReleaseObs = of({ "version": "0.0.3" }); spyOn(http, 'get').and.returnValue(resReleaseObs); spyOn(versionService, 'getVersion').and.returnValue(clientReleaseObs); - connectivityService.getVersionStatus() + await connectivityService.getVersionStatus() .then(res => { expect(res["client-version"]).toEqual("0.0.3") expect(res["release-version"]).toEqual("0.0.1") @@ -200,11 +200,11 @@ describe('ConnectivityService', () => { describe('getApiAvailability', () => { - it('should return the number of configured addresses', () => { + it('should return the number of configured addresses', async () => { let expectedAddressesObs = of(mailchainTestService.senderAddressesObserveResponse()) spyOn(addressesService, 'getAddressesResponse').and.returnValue(expectedAddressesObs); - connectivityService.getApiAvailability().then(res => { + await connectivityService.getApiAvailability().then(res => { expect(res["addresses"]).toEqual(2) expect(res["status"]).toEqual("ok") expect(res["code"]).toEqual(200) @@ -212,11 +212,11 @@ describe('ConnectivityService', () => { }) }); - it('should return 0 addresses when none are configured', () => { + it('should return 0 addresses when none are configured', async () => { let expectedAddressesObs = of(mailchainTestService.senderAddressesObserveResponseNoAddress()) spyOn(addressesService, 'getAddressesResponse').and.returnValue(expectedAddressesObs); - connectivityService.getApiAvailability().then(res => { + await connectivityService.getApiAvailability().then(res => { expect(res["addresses"]).toEqual(0) expect(res["status"]).toEqual("ok") expect(res["code"]).toEqual(200) @@ -227,11 +227,11 @@ describe('ConnectivityService', () => { xit('should return error and message when the client is not available', () => { // TODO add test for error scenario }); - it('should return status "ok" when client is running and configured', () => { + it('should return status "ok" when client is running and configured', async () => { let expectedAddressesObs = of(mailchainTestService.senderAddressesObserveResponse()) spyOn(addressesService, 'getAddressesResponse').and.returnValue(expectedAddressesObs); - connectivityService.getApiAvailability().then(res => { + await connectivityService.getApiAvailability().then(res => { expect(res["status"]).toEqual("ok") }) }); diff --git a/src/app/services/mailchain/messages/send.service.spec.ts b/src/app/services/mailchain/messages/send.service.spec.ts index 045e89a..ebc519e 100644 --- a/src/app/services/mailchain/messages/send.service.spec.ts +++ b/src/app/services/mailchain/messages/send.service.spec.ts @@ -119,7 +119,7 @@ describe('SendService', () => { expect(outboundMailObject.envelope).toBe("0x01") }) - it('should error on send if envelope type is empty in the outbound mail', () => { + xit('should error on send if envelope type is empty in the outbound mail', () => { // TODO add test for: should error on send if envelope type is empty in the outbound mail // let outboundMailObject = mailchainTestService.outboundMailObject() // outboundMailObject.envelope = "" @@ -130,7 +130,7 @@ describe('SendService', () => { expect(outboundMailObject["message"]["public-key-encoding"]).toBe("hex/0x-prefix") }) - it('should error on send if public-key-encoding is empty in the outbound mail', () => { + xit('should error on send if public-key-encoding is empty in the outbound mail', () => { // TODO add test for: should error on send if public-key-encoding is empty in the outbound mail // let outboundMailObject = mailchainTestService.outboundMailObject() // outboundMailObject["message"]["public-key-encoding"] = "" @@ -141,7 +141,7 @@ describe('SendService', () => { expect(outboundMailObject["message"]["public-key-kind"]).toBe("secp256k1") }) - it('should error on send if public-key-kind is empty in the outbound mail', () => { + xit('should error on send if public-key-kind is empty in the outbound mail', () => { // TODO add test for: should error on send if public-key-kind is empty in the outbound mail // let outboundMailObject = mailchainTestService.outboundMailObject() // outboundMailObject["message"]["public-key-kind"] = "" @@ -152,7 +152,7 @@ describe('SendService', () => { expect(outboundMailObject["encryption-method-name"]).toBe("aes256cbc") }) - it('should error on send if encryption-method-name is empty in the outbound mail', () => { + xit('should error on send if encryption-method-name is empty in the outbound mail', () => { // TODO add test for: should error on send if encryption-method-name is empty in the outbound mail // let outboundMailObject = mailchainTestService.outboundMailObject() // outboundMailObject["encryption-method-name"] = "" @@ -163,7 +163,7 @@ describe('SendService', () => { expect(outboundMailObject["envelope"]).not.toBeUndefined() }) - it('should error on send if `envelope` is empty in the outbound mail', () => { + xit('should error on send if `envelope` is empty in the outbound mail', () => { // TODO add test for: should error on send if envelope is empty in the outbound mail }) From 1486057147105567bb1c3a531b0bc72594ceab7f Mon Sep 17 00:00:00 2001 From: Tim Boeckmann Date: Tue, 7 Jul 2020 00:04:37 +0100 Subject: [PATCH 6/8] fix test; remove hard-coded envelope value for OutboundMail --- .../inbox/inbox-compose/inbox-compose.component.spec.ts | 7 ++++++- src/app/models/outbound-mail.ts | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/app/inbox/inbox-compose/inbox-compose.component.spec.ts b/src/app/inbox/inbox-compose/inbox-compose.component.spec.ts index b15b571..ff6f296 100644 --- a/src/app/inbox/inbox-compose/inbox-compose.component.spec.ts +++ b/src/app/inbox/inbox-compose/inbox-compose.component.spec.ts @@ -54,7 +54,12 @@ describe('InboxComposeComponent', () => { class EnvelopeServiceStub { getEnvelope() { - return envelopes // set envelope in test + if (envelopes) { + return envelopes // set envelope in test + } else { + return [{ "type": "0x01", "description": "Private Message Stored with MLI" }] + } + } } class PublicKeyServiceStub { diff --git a/src/app/models/outbound-mail.ts b/src/app/models/outbound-mail.ts index ddf3786..a40de5a 100644 --- a/src/app/models/outbound-mail.ts +++ b/src/app/models/outbound-mail.ts @@ -11,7 +11,7 @@ export class OutboundMail { "public-key-kind": "secp256k1", "subject": "" }; - public "envelope": string = "0x01"; + public "envelope": string = ""; public "encryption-method-name": string = "aes256cbc"; public "content-type": string = "text/plain; charset=\"UTF-8\""; } From 5261df09b5cba15931fea6ea1191e0428b01c44e Mon Sep 17 00:00:00 2001 From: Tim Boeckmann Date: Sat, 11 Jul 2020 19:33:00 +0100 Subject: [PATCH 7/8] update test config --- src/app/test/test-helpers/mailchain-test.service.ts | 3 +++ src/karma.conf.js | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app/test/test-helpers/mailchain-test.service.ts b/src/app/test/test-helpers/mailchain-test.service.ts index 0f9704f..7d06758 100644 --- a/src/app/test/test-helpers/mailchain-test.service.ts +++ b/src/app/test/test-helpers/mailchain-test.service.ts @@ -23,6 +23,9 @@ export class MailchainTestService { "public-key-kind": "secp256k1", "subject": "Test message", } + outboundMailObject["envelope"] = "0x05" + outboundMailObject["encryption-method-name"] = "aes256cbc" + outboundMailObject["content-type"] = "text/plain; charset=\"UTF-8\"" return outboundMailObject } diff --git a/src/karma.conf.js b/src/karma.conf.js index 49f67d5..cdd2608 100644 --- a/src/karma.conf.js +++ b/src/karma.conf.js @@ -26,7 +26,8 @@ module.exports = function (config) { type: 'lcov', // lcov or lcovonly are required for generating lcov.info files dir: 'coverage/' }, - reporters: ['progress', 'kjhtml', 'coverage-istanbul', 'coveralls', 'spec'], + // reporters: ['progress', 'kjhtml', 'coverage-istanbul', 'coveralls', 'spec'], + reporters: ['progress', 'kjhtml', 'coverage-istanbul', 'coveralls'], port: 9876, colors: true, logLevel: config.LOG_INFO, From 11f729e9bb78e20b45c96c550a086e17ff3c7b81 Mon Sep 17 00:00:00 2001 From: Tim Boeckmann Date: Sat, 11 Jul 2020 19:34:01 +0100 Subject: [PATCH 8/8] implement envelopes --- .../inbox-compose.component.html | 61 ++++++++++--------- .../inbox-compose.component.spec.ts | 11 ++-- .../inbox-compose/inbox-compose.component.ts | 12 ++-- src/app/models/mail.ts | 1 - .../mailchain/mailchain.service.spec.ts | 10 +-- .../services/mailchain/mailchain.service.ts | 24 ++++---- .../mailchain/messages/send.service.spec.ts | 4 +- 7 files changed, 65 insertions(+), 58 deletions(-) diff --git a/src/app/inbox/inbox-compose/inbox-compose.component.html b/src/app/inbox/inbox-compose/inbox-compose.component.html index 5174854..ba9237e 100644 --- a/src/app/inbox/inbox-compose/inbox-compose.component.html +++ b/src/app/inbox/inbox-compose/inbox-compose.component.html @@ -12,7 +12,7 @@

Compose New

- +
@@ -32,9 +32,9 @@

Compose New

-
+
- +
@@ -65,27 +65,12 @@

Compose New

- -
- -
-
- -
-
-
-
- +
@@ -98,21 +83,41 @@

Compose New

-
-
+ +
- -
- - + +
+
+ + + + + + + +
- + + +
+
+ + +
+
+
- diff --git a/src/app/inbox/inbox-compose/inbox-compose.component.spec.ts b/src/app/inbox/inbox-compose/inbox-compose.component.spec.ts index ff6f296..9379ab5 100644 --- a/src/app/inbox/inbox-compose/inbox-compose.component.spec.ts +++ b/src/app/inbox/inbox-compose/inbox-compose.component.spec.ts @@ -165,24 +165,23 @@ describe('InboxComposeComponent', () => { describe('handling the envelope', () => { it('should initialize an envelope in the "envelope" field using an available envelop', async () => { envelopes = mailchainTestService.envelopeTypeMli() - expect(component.model.envelope).toBe('') await component.ngOnInit(); fixture.detectChanges() - expect(component.model.envelope).toBe('0x01') + expect(component.envelopeType).toBe('0x01') }) it('should initialize an envelope in the "envelope" field using an available envelop', async () => { envelopes = mailchainTestService.envelopeTypeIpfs() await component.ngOnInit(); fixture.detectChanges() - expect(component.model.envelope).toBe('0x02') + expect(component.envelopeType).toBe('0x02') }) it('should populate the envelope_type dropdown with the first value if there are multiple envelopes available', async () => { envelopes = mailchainTestService.envelopeTypesMultiple() await component.ngOnInit(); fixture.detectChanges() - expect(component.model.envelope).toBe('0x01') + expect(component.envelopeType).toBe('0x01') }) }) @@ -472,6 +471,7 @@ describe('InboxComposeComponent', () => { "public-key": "1234567890abcd", subject: 'Test Message' } + // outboundMail.envelope = "0x01" beforeEach(() => { component.model.to = currentAccount @@ -479,6 +479,7 @@ describe('InboxComposeComponent', () => { component.model.subject = "Test Message" component.model.body = "This is a test message" component.currentNetwork = 'testnet' + component.envelopeType = "0x05" spyOn(publicKeyService, "getPublicKeyFromAddress").and.callFake(() => { return of({ @@ -511,7 +512,7 @@ describe('InboxComposeComponent', () => { it('should generate a message', () => { component.onSubmit(); - expect(mailchainService.generateMail).toHaveBeenCalledWith(mail, 'html') + expect(mailchainService.generateMail).toHaveBeenCalledWith(mail, 'html', '0x05') }) diff --git a/src/app/inbox/inbox-compose/inbox-compose.component.ts b/src/app/inbox/inbox-compose/inbox-compose.component.ts index 346f506..6cf1ab0 100644 --- a/src/app/inbox/inbox-compose/inbox-compose.component.ts +++ b/src/app/inbox/inbox-compose/inbox-compose.component.ts @@ -51,6 +51,8 @@ export class InboxComposeComponent implements OnInit { public Editor = ClassicEditor; public inputContentType = "html" public contentTypeSwitchLabel: string = "" + public envelopeType + public envelopeDescription @ViewChild('editor', { static: false }) public editorComponent: CKEditorComponent; @@ -72,7 +74,6 @@ export class InboxComposeComponent implements OnInit { this.model.from = "" this.model.subject = "" this.model.body = "" - this.model.envelope = "" } /** @@ -289,7 +290,8 @@ export class InboxComposeComponent implements OnInit { */ private setFirstEnvelopeInEnvelopeDropdown() { if (this.envelopes != undefined) { - this.model.envelope = this.envelopes[0]["type"] + this.envelopeType = this.envelopes[0]["type"] + this.envelopeDescription = this.envelopes[0]["description"] } } @@ -452,7 +454,7 @@ export class InboxComposeComponent implements OnInit { ).subscribe(res => { this.model.publicKey = res["body"]["public-key"] - var outboundMail = this.generateMessage(this.model, this.inputContentType) + var outboundMail = this.generateMessage(this.model, this.inputContentType, this.envelopeType) this.sendMessage(outboundMail).subscribe(res => { self.initMail(); @@ -473,8 +475,8 @@ export class InboxComposeComponent implements OnInit { * Builds the OutboundMail object for sending * @param mailObj The form Mail object */ - private generateMessage(mailObj: Mail, inputContentType: string): OutboundMail { - return this.mailchainService.generateMail(mailObj, inputContentType) + private generateMessage(mailObj: Mail, inputContentType: string, envelope: string): OutboundMail { + return this.mailchainService.generateMail(mailObj, inputContentType, envelope) } /** diff --git a/src/app/models/mail.ts b/src/app/models/mail.ts index db1b866..4a3de5e 100644 --- a/src/app/models/mail.ts +++ b/src/app/models/mail.ts @@ -4,5 +4,4 @@ export class Mail { public subject: string = ""; public body: string = ""; public publicKey: string = ""; - public envelope: string = ""; } \ No newline at end of file diff --git a/src/app/services/mailchain/mailchain.service.spec.ts b/src/app/services/mailchain/mailchain.service.spec.ts index 655ecc1..3fb2bb2 100644 --- a/src/app/services/mailchain/mailchain.service.spec.ts +++ b/src/app/services/mailchain/mailchain.service.spec.ts @@ -237,20 +237,20 @@ describe('MailchainService', () => { "public-key-kind": "secp256k1", "subject": "Test message", } - + outboundMailObject["envelope"] = "0x05" it('should return valid outputs when given a valid Mail object', () => { - let response = mailchainService.generateMail(mailObject, "plaintext") - + let response = mailchainService.generateMail(mailObject, "plaintext", "0x05") + expect(response).toEqual(outboundMailObject) }) it('should return valid content type for plaintext', () => { - let response = mailchainService.generateMail(mailObject, "plaintext") + let response = mailchainService.generateMail(mailObject, "plaintext", "0x01") expect(response["content-type"]).toEqual('text/plain; charset=\"UTF-8\"') }) it('should return valid content type for html', () => { - let response = mailchainService.generateMail(mailObject, "html") + let response = mailchainService.generateMail(mailObject, "html", "0x01") expect(response["content-type"]).toEqual('text/html; charset=\"UTF-8\"') }) diff --git a/src/app/services/mailchain/mailchain.service.ts b/src/app/services/mailchain/mailchain.service.ts index 8694b17..7e84232 100644 --- a/src/app/services/mailchain/mailchain.service.ts +++ b/src/app/services/mailchain/mailchain.service.ts @@ -18,27 +18,27 @@ export class MailchainService { * @param mailObj the Mail object * @param contentType the content type [ 'text/plain; charset=\"UTF-8\"' | 'text/html; charset=\"UTF-8\"' ] */ - generateMail(mailObj, contentType): OutboundMail { - - var envelope = new OutboundMail - envelope.message["body"] = mailObj["body"] - envelope.message["headers"]["from"] = mailObj["from"] - envelope.message["headers"]["reply-to"] = mailObj["from"] //TODO: handle reply-to - envelope.message["headers"]["to"] = mailObj["to"] - envelope.message["public-key"] = mailObj["publicKey"] - envelope.message["subject"] = mailObj["subject"] + generateMail(mailObj, contentType, envelope): OutboundMail { + var outboundMail = new OutboundMail + outboundMail.message["body"] = mailObj["body"] + outboundMail.message["headers"]["from"] = mailObj["from"] + outboundMail.message["headers"]["reply-to"] = mailObj["from"] //TODO: handle reply-to + outboundMail.message["headers"]["to"] = mailObj["to"] + outboundMail.message["public-key"] = mailObj["publicKey"] + outboundMail.message["subject"] = mailObj["subject"] + outboundMail["envelope"] = envelope switch (contentType) { case "html": - envelope["content-type"] = 'text/html; charset=\"UTF-8\"' + outboundMail["content-type"] = 'text/html; charset=\"UTF-8\"' break; default: - envelope["content-type"] = 'text/plain; charset=\"UTF-8\"' + outboundMail["content-type"] = 'text/plain; charset=\"UTF-8\"' break; } - return envelope + return outboundMail } diff --git a/src/app/services/mailchain/messages/send.service.spec.ts b/src/app/services/mailchain/messages/send.service.spec.ts index ebc519e..d835643 100644 --- a/src/app/services/mailchain/messages/send.service.spec.ts +++ b/src/app/services/mailchain/messages/send.service.spec.ts @@ -114,9 +114,9 @@ describe('SendService', () => { req.flush(body); }) - it('should specify envelope type "0x01" in the outbound mail', () => { + it('should specify envelope type "0x05" in the outbound mail', () => { let outboundMailObject = mailchainTestService.outboundMailObject() - expect(outboundMailObject.envelope).toBe("0x01") + expect(outboundMailObject.envelope).toBe("0x05") }) xit('should error on send if envelope type is empty in the outbound mail', () => {