Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

Commit

Permalink
Merge branch 'staging' into dependabot/npm_and_yarn/npm-registry-fetc…
Browse files Browse the repository at this point in the history
…h-4.0.5

* staging:
  implement envelopes
  update test config
  fix test; remove hard-coded envelope value for OutboundMail
  clean up tests
  add tests handle envelopes
  add envelopeService
  add tests and helpers
  tweak tests
  • Loading branch information
tboeckmann committed Jul 11, 2020
2 parents 59d5ec6 + 11f729e commit dbcaa80
Show file tree
Hide file tree
Showing 12 changed files with 285 additions and 67 deletions.
50 changes: 36 additions & 14 deletions src/app/inbox/inbox-compose/inbox-compose.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h4>Compose <span class="fw-semi-bold">New</span></h4>

<!-- From Field -->
<div class="form-group row">
<label for="from" class="col-form-label col-sm-2 col-md- col-lg-2">From:</label>
<label for="from" class="col-form-label col-sm-2 col-md-2 col-lg-2">From:</label>
<div class="col-md-10 col-lg-9">
<div class="input-group mb-2 row">
<div class="input-group-prepend">
Expand All @@ -31,11 +31,10 @@ <h4>Compose <span class="fw-semi-bold">New</span></h4>

<!-- ./From Field -->


<!-- To Field -->
<div class="form-group">
<div class="form-group mb-0">
<div class="row">
<label for="to" class="col-form-label col-sm-2 col-md- col-lg-2">To:</label>
<label for="to" class="col-form-label col-sm-2 col-md-2 col-lg-2">To:</label>
<div class="col-md-10 col-lg-9">
<div class="input-group row">
<div class="input-group-prepend">
Expand Down Expand Up @@ -65,10 +64,13 @@ <h4>Compose <span class="fw-semi-bold">New</span></h4>
</div>
<!-- ./To Field -->




<!-- Subject Field -->
<div class="form-group row">

<label for="subject" class="col-form-label col-sm-2 col-md- col-lg-2">Subject:</label>
<label for="subject" class="col-form-label col-sm-2 col-md-2 col-lg-2">Subject:</label>

<div class="col-md-10 col-lg-9">
<div class="input-group mb-2 row">
Expand All @@ -81,21 +83,41 @@ <h4>Compose <span class="fw-semi-bold">New</span></h4>
<!-- ./Subject Field -->


<!-- Plain/HTML toggle field -->
<div class="form-group row">
<div class="col-md-10 col-lg-9 offset-md-2 offset-sm-0">
<label for="envelope" class="col-form-label col-sm-2 col-md-2 col-lg-2">Envelope Type:</label>
<div class="col-md-10 col-lg-10">
<div class="input-group mb-2 row">

<div class="custom-control custom-switch content-type-switch">
<input type="checkbox" class="custom-control-input" id="contentTypeSwitch" (click)="convertToPlainText()"
[disabled]="inputContentType == 'plaintext'">
<label class="custom-control-label" for="contentTypeSwitch">{{contentTypeSwitchLabel}}</label>
<!-- Envelope Field -->
<div class="col-md-7 col-lg-7">
<div class="input-group mb-2 row">
<!-- <1 Envelope -->
<input type="hidden" *ngIf="envelopeType && envelopes.length <= 1" [(ngModel)]="envelope"
name="envelope">
<input type="text" *ngIf="envelopeType && envelopes.length <= 1"
value="{{envelopeDescription}} ({{envelopeType}})" name="envelope" class="form-control" disabled>
<!-- ./ <1 Envelope -->
<!-- >1 Envelope -->
<select class="form-control" [(ngModel)]="envelope" name="envelope" *ngIf="envelopes.length > 1">
<option *ngFor="let envelope of envelopes; let i = index" [value]="envelope.type">
{{envelope.description}} ({{envelope.type}})
</option>
</select>
<!-- ./ >1 Envelope -->
</div>
</div>

<!-- ./Envelope Field -->
<!-- Plain/HTML toggle field -->
<div class="col-md-5 col-lg-4">
<div class="custom-control custom-switch content-type-switch">
<input type="checkbox" class="custom-control-input" id="contentTypeSwitch"
(click)="convertToPlainText()" [disabled]="inputContentType == 'plaintext'">
<label class="custom-control-label" for="contentTypeSwitch">{{contentTypeSwitchLabel}}</label>
</div>
</div>
<!-- ./Plain/HTML toggle field -->
</div>
</div>
</div>
<!-- ./Plain/HTML toggle field -->

<!-- Body Field -->
<!-- Plaintext Field -->
Expand Down
44 changes: 43 additions & 1 deletion src/app/inbox/inbox-compose/inbox-compose.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -43,12 +44,24 @@ describe('InboxComposeComponent', () => {
const currentAccount2 = '0x0123456789abcdef0123456789abcdef01234567';
const ensName = 'mailchain.eth';
const addresses = [currentAccount, currentAccount2];
let envelopes: Array<any>

class AddressesServiceStub {
getAddresses() {
return addresses
}
}

class EnvelopeServiceStub {
getEnvelope() {
if (envelopes) {
return envelopes // set envelope in test
} else {
return [{ "type": "0x01", "description": "Private Message Stored with MLI" }]
}

}
}
class PublicKeyServiceStub {
getPublicKeyFromAddress(publicAddress, network) {
return of(['1234567890'])
Expand Down Expand Up @@ -77,6 +90,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 },
Expand Down Expand Up @@ -147,8 +161,34 @@ 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 () => {
envelopes = mailchainTestService.envelopeTypeMli()
await component.ngOnInit();
fixture.detectChanges()
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.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.envelopeType).toBe('0x01')
})

})

});


describe('when composing a plaintext reply', () => {
beforeEach(() => {
component.currentMessage = mailchainTestService.inboundMessage();
Expand Down Expand Up @@ -431,13 +471,15 @@ describe('InboxComposeComponent', () => {
"public-key": "1234567890abcd",
subject: 'Test Message'
}
// outboundMail.envelope = "0x01"

beforeEach(() => {
component.model.to = currentAccount
component.model.from = currentAccount2
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({
Expand Down Expand Up @@ -470,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')

})

Expand Down
34 changes: 30 additions & 4 deletions src/app/inbox/inbox-compose/inbox-compose.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -32,6 +33,8 @@ export class InboxComposeComponent implements OnInit {

public model = new Mail()
public fromAddresses: Array<any> = []
public envelopes: Array<any> = []

public sendMessagesDisabled: boolean = false;
private subscription
public currentRecipientValue
Expand All @@ -48,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;

Expand All @@ -56,6 +61,7 @@ export class InboxComposeComponent implements OnInit {
private sendService: SendService,
private publicKeyService: PublicKeyService,
private addressesService: AddressesService,
private envelopeService: EnvelopeService,
private nameserviceService: NameserviceService,
private modalService: BsModalService,
) { }
Expand Down Expand Up @@ -97,12 +103,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
Expand Down Expand Up @@ -271,6 +284,17 @@ 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.envelopeType = this.envelopes[0]["type"]
this.envelopeDescription = this.envelopes[0]["description"]
}
}

/**
* Initialise the message.
* If it's a new message, fields will be blank.
Expand All @@ -279,10 +303,12 @@ export class InboxComposeComponent implements OnInit {
*/
async ngOnInit(): Promise<void> {
await this.setFromAddressList()
await this.setEnvelopeList()
this.setContentTypeForView()
this.initMail()
this.initEditor()
this.setCurrentAccountInFromAddressDropdown()
this.setFirstEnvelopeInEnvelopeDropdown()
this.handleReplyFields()
this.setupRecipientAddressLookupSubscription()
}
Expand Down Expand Up @@ -428,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();
Expand All @@ -449,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)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/app/models/outbound-mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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\"";
}
Expand Down

0 comments on commit dbcaa80

Please sign in to comment.