Skip to content

Commit

Permalink
CC-559: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cavanmflynn committed Mar 22, 2019
1 parent 37363bb commit 5fd1885
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
6 changes: 1 addition & 5 deletions test/helpers/grpc-stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ module.exports = function grpcStub(
lightning = LightningStub,
walletUnlocker = WalletUnlockerStub
) {
// provide mock cert if none specified
const config = Object.assign({}, options);
if (!config.tls || !config.cert) config.cert = 'cert';

return Object.assign(
{
Metadata,
Expand All @@ -51,7 +47,7 @@ module.exports = function grpcStub(
},
}),
},
config
options
);
};

Expand Down
29 changes: 25 additions & 4 deletions test/lnrpc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const readFile = promisify(fs.readFile);
const writeFile = promisify(fs.writeFile);

describe('Lnrpc Factory', () => {
const certStub = 'cert';

describe('TLS settings', () => {
it('should throw an error when tls file not found', () =>
createLnrpc({tls: './not-a-file.cert'})
Expand Down Expand Up @@ -193,7 +195,10 @@ describe('Lnrpc Factory', () => {
// ensure rpc.proto file gets removed
}

await createLnrpc({grpc: grpcStub()});
await createLnrpc({
grpc: grpcStub(),
cert: certStub,
});

try {
await stat(protoDest);
Expand All @@ -203,7 +208,10 @@ describe('Lnrpc Factory', () => {
});

it('should generate a `rpc.proto` without google annotations', async () => {
await createLnrpc({grpc: grpcStub()});
await createLnrpc({
grpc: grpcStub(),
cert: certStub,
});

const root = await pkgDir(__dirname);
const rpcProto = await readFile(join(root, 'rpc.proto'), 'utf-8');
Expand All @@ -227,6 +235,7 @@ describe('Lnrpc Factory', () => {
},
},
grpc: grpcStub(),
cert: certStub,
});
});

Expand All @@ -238,6 +247,7 @@ describe('Lnrpc Factory', () => {
equal(actual, expected, 'defaults to expected server');
return new LightningStub();
}),
cert: certStub,
});
});

Expand All @@ -250,20 +260,28 @@ describe('Lnrpc Factory', () => {
equal(actual, expected, 'recieved configured server');
return new LightningStub();
}),
cert: certStub,
});
});
});

describe('proxy instance', () => {
it('should provide access to GRPC Package Definition', () => {
return createLnrpc({grpc: grpcStub()}).then((lnrpc) => {
return createLnrpc({
grpc: grpcStub(),
cert: certStub,
}).then((lnrpc) => {
equal(typeof lnrpc.description, 'object');
});
});

it('should provide access to the lightning instance', () => {
const expected = {};
return createLnrpc({grpc: grpcStub(), lightning: expected}).then(
return createLnrpc({
grpc: grpcStub(),
lightning: expected,
cert: certStub}
).then(
(lnrpc) => {
equal(lnrpc.lightning, expected);
}
Expand All @@ -275,6 +293,7 @@ describe('Lnrpc Factory', () => {
return createLnrpc({
grpc: grpcStub(),
walletUnlocker: expected,
cert: certStub,
}).then((lnrpc) => {
equal(lnrpc.walletUnlocker, expected);
});
Expand All @@ -284,6 +303,7 @@ describe('Lnrpc Factory', () => {
return createLnrpc({
grpc: grpcStub(),
lightning: {test: () => {}},
cert: certStub,
}).then((lnrpc) => {
equal(typeof lnrpc.test, 'function');
});
Expand All @@ -293,6 +313,7 @@ describe('Lnrpc Factory', () => {
return createLnrpc({
grpc: grpcStub(),
walletUnlocker: {test: () => {}},
cert: certStub,
}).then((lnrpc) => {
equal(typeof lnrpc.test, 'function');
});
Expand Down
4 changes: 4 additions & 0 deletions test/release.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const {LightningStub} = grpcStub;
const {equal} = assert;

describe('Release API', () => {
const certStub = 'cert';

it('should expose a lnrpc factory function as default', () => {
equal(typeof createLnrpc, 'function');
});
Expand All @@ -20,6 +22,7 @@ describe('Release API', () => {

return createLnrpc({
grpc: grpcStub({}, LightningCustomStub),
cert: certStub,
}).then((lnrpc) => {
equal(typeof lnrpc.walletBalance, 'function');
});
Expand All @@ -35,6 +38,7 @@ describe('Release API', () => {

return createLnrpc({
grpc: grpcStub({}, LightningStub, WalletUnlockerStub),
cert: certStub,
}).then((lnrpc) => {
equal(typeof lnrpc.walletUnlocker.initWallet, 'function');
});
Expand Down

0 comments on commit 5fd1885

Please sign in to comment.