Skip to content

Commit a8bdc07

Browse files
authored
Merge branch 'dev' into tabBugs
2 parents ea6b148 + 3d0411c commit a8bdc07

31 files changed

+369
-229
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,7 @@ ehthumbs.db
5555
# Windows shortcuts #
5656
#####################
5757
*.lnk
58+
59+
# proto files #
60+
#####################
61+
*.proto

__tests__/businessReducer.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('Business reducer', () => {
4242
newRequestBody: {
4343
bodyContent: '',
4444
bodyVariables: '',
45-
bodyType: 'none',
45+
bodyType: 'raw',
4646
rawType: 'Text (text/plain)',
4747
JSONFormatted: true,
4848
},
@@ -346,6 +346,28 @@ describe('Business reducer', () => {
346346
graphQL: true
347347
}
348348
}
349+
const requestStreamsAction = {
350+
type: 'SET_NEW_REQUEST_STREAMS',
351+
payload: {
352+
353+
streamsArr: [],
354+
count: 0,
355+
streamContent: [],
356+
selectedPackage: 'helloworld',
357+
selectedRequest: 'helloRequest',
358+
selectedService: 'hello',
359+
selectedStreamingType: null,
360+
initialQuery: null,
361+
queryArr: null,
362+
protoPath: null,
363+
services: null,
364+
365+
},
366+
}
367+
it('sets the newRequestStreams on SET_NEW_REQUEST_STREAMS', () => {
368+
const { newRequestStreams } = reducer(state, requestStreamsAction);
369+
expect(newRequestStreams).toEqual(requestStreamsAction.payload);
370+
})
349371
it('sets the newRequestFields on POST', () => {
350372
const { newRequestFields } = reducer(state, postAction);
351373
expect(newRequestFields).toEqual(postAction.payload);

__tests__/composerTests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('GraphQL Composer', () => {
7777
},
7878
newRequestBody: {
7979
bodyContent: '',
80-
bodyType: 'none',
80+
bodyType: 'raw',
8181
rawType: 'Text (text/plain)',
8282
JSONFormatted: true,
8383
bodyVariables: ''

__tests__/protoParserTests.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import protoParser from '../src/client/components/composer/protos/protoParser';
2+
3+
4+
describe('testing protoParser', ()=> {
5+
6+
const protoFile = `syntax = 'proto3';
7+
8+
package helloworld;
9+
10+
// The greeting service definition.
11+
service Greeter {
12+
// Sends a greeting
13+
rpc SayHello (HelloRequest) returns (HelloReply) {}
14+
rpc SayHelloCS (stream HelloRequest) returns (HelloReply) {}
15+
rpc SayHellos (HelloRequest) returns (stream HelloReply) {}
16+
rpc SayHelloBidi (stream HelloRequest) returns (stream HelloReply) {}
17+
}
18+
19+
// The request message containing the user's name.
20+
message HelloRequest {
21+
string name = 1;
22+
}
23+
24+
// The response message containing the greetings
25+
message HelloReply {
26+
string message = 1;
27+
}
28+
29+
// The request message containing the user's name.
30+
message HelloHowOldRequest {
31+
int32 age = 1;
32+
}
33+
message HelloAge {
34+
int32 age = 1;
35+
}`
36+
describe('parser parses protos correctly', ()=> {
37+
it('should get packageName', () => {
38+
const parsedProto = protoParser(protoFile)
39+
.then(data => {
40+
// console.log(d)
41+
expect(data.packageName).toEqual('helloworld')
42+
})
43+
44+
})
45+
it('should get serviceArray', () => {
46+
const testArr = [{
47+
messages: [{}, {}, {}, {}],
48+
name: 'Greeter',
49+
packageName: 'helloworld',
50+
rpcs: [{}, {}, {}, {}],
51+
52+
}]
53+
const parsedProto = protoParser(protoFile)
54+
.then(data => {
55+
// console.log(d)
56+
expect(data.serviceArr[0].messages).toHaveLength(4);
57+
expect(data.serviceArr[0].rpcs).toHaveLength(4);
58+
expect(data.serviceArr[0].name).toEqual('Greeter');
59+
expect(data.serviceArr[0].packageName).toEqual('helloworld');
60+
})
61+
62+
})
63+
64+
it('should fill message content', () => {
65+
const testArr = [{
66+
messages: [
67+
{name: "HelloRequest", def: {name: {type: "TYPE_STRING", nested: false, dependent: ''}}},
68+
{name: "HelloRequest", def: {name: {type: "TYPE_STRING", nested: false, dependent: ''}}},
69+
{name: "HelloRequest", def: {name: {type: "TYPE_STRING", nested: false, dependent: ''}}},
70+
{name: "HelloRequest", def: {name: {type: "TYPE_STRING", nested: false, dependent: ''}}}
71+
],
72+
name: 'Greeter',
73+
packageName: 'helloworld',
74+
rpcs: [{}, {}, {}, {}],
75+
76+
}]
77+
const parsedProto = protoParser(protoFile)
78+
.then(data => {
79+
expect(data.serviceArr[0].messages[0]).toEqual(testArr[0].messages[0]);
80+
expect(data.serviceArr[0].messages[0].def.name.type).toEqual("TYPE_STRING");
81+
})
82+
83+
})
84+
85+
86+
})
87+
})
88+

__tests__/responseTests.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('ResponseContainer', () => {
2626
wrapper.setState({ openTab: 'Response Headers' });
2727
expect(wrapper.find('ResponseHeadersDisplay')).toBeTruthy();
2828
});
29+
2930

3031
it('should render Response Cookies when selected', () => {
3132
const wrapper = shallow(<ResponseContainer {...props} />);
@@ -47,15 +48,35 @@ describe('ResponseContainer', () => {
4748
const wrapper = shallow(<ResponseContainer {...props} />);
4849
expect(wrapper.find('ResponseEventsDisplay')).toBeTruthy();
4950
});
51+
52+
props = {
53+
content: {
54+
gRPC: true,
55+
request: {
56+
method: null
57+
},
58+
}
59+
}
60+
it('gRPC req should render Response Metadata when selected', () => {
61+
const wrapper = shallow(<ResponseContainer {...props} />);
62+
wrapper.setState({ openTab: 'Response Metadata' });
63+
expect(wrapper.find('ResponseHeadersDisplay')).toBeTruthy();
64+
});
65+
5066
});
5167

5268
describe('ResponseTabs', () => {
5369
it('should render three tabs', () => {
54-
const wrapper = shallow(<ResponseTabs />);
70+
const wrapper = shallow(<ResponseTabs content={'not grpc'}/>);
5571
expect(wrapper.find('Tab')).toHaveLength(3);
5672
});
73+
it('grpc should render two tabs', () => {
74+
const wrapper = shallow(<ResponseTabs content={{gRPC: true}}/>);
75+
expect(wrapper.find('Tab')).toHaveLength(2);
76+
});
5777
});
5878

79+
5980
describe('ResponseEventsDisplay', () => {
6081
it('if SSE, should render event rows', () => {
6182
const props = {
@@ -67,16 +88,7 @@ describe('ResponseEventsDisplay', () => {
6788
const wrapper = shallow(<ResponseEventsDisplay {...props} />);
6889
expect(wrapper.find('SSERow')).toHaveLength(2);
6990
});
70-
// it('if gRPC, should render all events', () => {
71-
// const props = {
72-
// response: {
73-
// headers: { 'content-type': 'text/event-stream' },
74-
// events: ['event 1', 'event 2'],
75-
// }
76-
// };
77-
// const wrapper = shallow(<ResponseEventsDisplay {...props} />);
78-
// expect(wrapper.find('JSONPretty').props.data).toHaveLength(2);
79-
// });
91+
8092
it('if not SSE, should render single event', () => {
8193
const props = {
8294
response: {

grpc_mockData/protos/hw2.proto

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ package helloworld;
55
// The greeting service definition.
66
service Greeter {
77
// Sends a greeting
8-
rpc SayHello (HelloRequest) returns (HelloReply) {}
8+
rpc SayHello (HelloRequest) returns (HelloReply) {} // single unary stream
9+
rpc SayHelloNested (HelloNestedRequest) returns (HelloNestedReply) {} // nested unary stream
910
rpc SayHelloCS (stream HelloRequest) returns (HelloReply) {}
1011
rpc SayHellos (HelloRequest) returns (stream HelloReply) {}
1112
rpc SayHelloBidi (stream HelloRequest) returns (stream HelloReply) {}
@@ -21,6 +22,16 @@ message HelloReply {
2122
string message = 1;
2223
}
2324

25+
message HelloNestedRequest {
26+
HelloRequest firstPerson = 1;
27+
HelloRequest secondPerson = 2;
28+
}
29+
30+
message HelloNestedReply {
31+
// create array of nested server response
32+
repeated HelloReply serverMessage = 1;
33+
34+
}
2435
// The request message containing the user's name.
2536
message HelloHowOldRequest {
2637
int32 age = 1;

grpc_mockData/server.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ function sayHello(ctx) {
3535
metadata.set('indeed', 'it do')
3636
// Watcher creates a watch execution context for the watch
3737
// The execution context provides scripts and templates with access to the watch metadata
38-
console.log("received metadata from client request", ctx.meta)
39-
// console.dir(ctx.metadata, { depth: 3, colors: true });
38+
console.log("received metadata from client request", ctx.metadata)
39+
console.dir(ctx.metadata, { depth: 3, colors: true });
4040
console.log(`got sayHello request name: ${ctx.req.name}`);
41-
41+
4242
// an alias to ctx.response.res
4343
// This is set only in case of DUPLEX calls, to the the gRPC call reference itself
4444
ctx.res = { message: "Hello " + ctx.req.name };
@@ -49,7 +49,28 @@ function sayHello(ctx) {
4949

5050
console.log(`set sayHello response: ${ctx.res.message}`);
5151
}
52+
// nested Unary stream
53+
54+
function sayHelloNested(ctx) {
55+
// create new metadata
56+
let metadata = new grpc.Metadata();
57+
metadata.set('it', 'works?')
58+
metadata.set('indeed', 'it do')
59+
// Watcher creates a watch execution context for the watch
60+
// The execution context provides scripts and templates with access to the watch metadata
61+
console.log("received metadata from client request", ctx.metadata)
62+
console.dir(ctx.metadata, { depth: 3, colors: true });
63+
// console.log("ctx line 64 from server.js", ctx)
64+
65+
// nested unary response call
66+
let firstPerson = ctx.req.firstPerson.name;
67+
let secondPerson = ctx.req.secondPerson.name;
68+
console.log("firstPerson line 68 from server.js:", firstPerson)
69+
ctx.res = {"serverMessage": [{message: "Hello! " + firstPerson}, {message: 'Hello! ' + secondPerson}]}
5270

71+
// send response header metadata object directly as an argument and that is set and sent
72+
ctx.sendMetadata(metadata)
73+
}
5374
// Server-Side Stream
5475
// used highland library to manage asynchronous data
5576
async function sayHellos(ctx) {
@@ -64,7 +85,9 @@ async function sayHellos(ctx) {
6485

6586
// alias for ctx.request.req
6687
// In case of UNARY and RESPONSE_STREAM calls it is simply the gRPC call's request
88+
6789
let reqMessages = {"message": 'hello!!! ' + ctx.req.name}
90+
6891
dataStream.push(reqMessages)
6992
reqMessages = dataStream
7093
let streamData = await hl(reqMessages)
@@ -80,6 +103,7 @@ async function sayHellos(ctx) {
80103
ctx.res.end()
81104
}
82105

106+
83107
// Client-Side stream
84108
function sayHelloCs (ctx) {
85109
// create new metadata
@@ -146,7 +170,7 @@ function sayHelloBidi(ctx) {
146170
*/
147171
function main() {
148172
const app = new Mali(PROTO_PATH, "Greeter");
149-
app.use({ sayHello, sayHellos, sayHelloCs, sayHelloBidi });
173+
app.use({ sayHello, sayHelloNested, sayHellos, sayHelloCs, sayHelloBidi });
150174
app.start(HOSTPORT);
151175
console.log(`Greeter service running @ ${HOSTPORT}`);
152176
}

src/assets/style/colors.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ $graytwo: #C4CED4;
3939
$graythree: #A9B0BE;
4040

4141
$gqlpink: #E00198;
42-
$gqlpinktwo: rgb(190, 62, 158);
42+
$gqlpinktwo: #BE3E9E;
4343

4444
$grpcorange: #E6781E;

src/assets/style/sidebar.scss

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,7 @@
171171
padding: 0px auto;
172172
text-align-last: center;
173173
width: 200px;
174-
&:focus {
175-
outline: 0 none;
176-
}
174+
outline: 0 none;
177175
&.http {
178176
background: $bluetwo;
179177
&:hover {
@@ -348,6 +346,11 @@
348346
text-align-last: center;
349347
width: 100%;
350348
outline: none;
349+
&:hover {
350+
color: $medbluegray;
351+
background: $huntergreen;
352+
border: 2px solid $litebluegray;
353+
}
351354
}
352355
.composer_textarea {
353356
background-color: $liteblack;

src/client/components/composer/NewRequest/BodyEntryForm.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class BodyEntryForm extends Component {
6666
})()
6767

6868
const arrowClass = this.state.show ? 'composer_subtitle_arrow-open' : 'composer_subtitle_arrow-closed';
69-
7069
const bodyContainerClass = this.state.show ? 'composer_bodyform_container-open' : 'composer_bodyform_container-closed';
7170

7271
return (

0 commit comments

Comments
 (0)