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

Commit

Permalink
add getProtocolNetworkAttributes to be used for any attribute for a p…
Browse files Browse the repository at this point in the history
…rotocol network
  • Loading branch information
tboeckmann committed Oct 11, 2020
1 parent d4df5bc commit be71a5c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 7 deletions.
47 changes: 40 additions & 7 deletions src/app/services/mailchain/protocols/protocols.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MailchainTestService } from 'src/app/test/test-helpers/mailchain-test.s

import { ProtocolsService } from './protocols.service';
import { HttpHelpersService } from '../../helpers/http-helpers/http-helpers.service';
import { of } from 'rxjs';

describe('ProtocolsService', () => {

Expand Down Expand Up @@ -48,15 +49,47 @@ describe('ProtocolsService', () => {
});
});

it('should get an array of protocols and networks', () => {
protocolsService.getProtocols().subscribe(res => {
expect(res).toEqual(serverResponse)

describe('getProtocols', () => {
it('should get an array of protocols and networks', () => {
protocolsService.getProtocols().subscribe(res => {
expect(res).toEqual(serverResponse)
});

// handle open connections
const req = httpTestingController.expectOne(desiredUrl);
expect(req.request.method).toBe("GET");
req.flush(serverResponse);
});
});

// handle open connections
const req = httpTestingController.expectOne(desiredUrl);
expect(req.request.method).toBe("GET");
req.flush(serverResponse);
describe('getProtocolsByName', () => {
it('should get the protocols by name', async () => {
spyOn(protocolsService,'getProtocols').and.returnValue(of(mailchainTestService.protocolsServerResponse()))
expect(await protocolsService.getProtocolsByName()).toEqual(["ethereum","substrate"])
});
});

describe('getProtocolNetworkAttributes', () => {
it('should return the attributes for a protocol network', async () => {
spyOn(protocolsService,'getProtocols').and.returnValue(of(mailchainTestService.protocolsServerResponse()))
expect(await protocolsService.getProtocolNetworkAttributes("ethereum","mainnet")).toEqual(
{
"name": "mainnet",
"id": "",
"nameservice-domain-enabled": true,
"nameservice-address-enabled": true
}
)
expect(await protocolsService.getProtocolNetworkAttributes("substrate","edgeware-mainnet")).toEqual(
{
"name": "edgeware-mainnet",
"id": "7",
"nameservice-domain-enabled": false,
"nameservice-address-enabled": false
}
)
});
});

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ export class ProtocolsServiceStub {
return ["ethereum", "substrate"]
}

async getProtocolNetworkAttributes(protocol: string, network: string) {
let res = this.mailchainTestService.protocolsServerResponse()
let attributes = {}
let p = res["protocols"].find(el => el["name"] == protocol)
attributes = p["networks"].find(nw => nw["name"] == network)
return attributes
}

public getProtocolsResponse() {
return of(this.mailchainTestService.protocolsObserveResponse())
}
Expand Down
12 changes: 12 additions & 0 deletions src/app/services/mailchain/protocols/protocols.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ export class ProtocolsService {
return protocols
}

/**
* Helper function to get and return the protocol & network attributes
*/
async getProtocolNetworkAttributes(protocol: string, network: string) {
let attributes = {}
await this.getProtocols().toPromise().then(res => {
let p = res["protocols"].find(el => el["name"] == protocol)
attributes = p["networks"].find(nw => nw["name"] == network)
})
return attributes
}

/**
* Returns the protocols response with status codes
*/
Expand Down

0 comments on commit be71a5c

Please sign in to comment.