Skip to content

Commit c577693

Browse files
feat: add enum unit test (#1037)
Add unit test for enum conversion #1028
1 parent f9d295b commit c577693

File tree

1 file changed

+78
-26
lines changed

1 file changed

+78
-26
lines changed

packages/packages/google-gax/test/unit/regapic.ts

Lines changed: 78 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -107,36 +107,88 @@ describe('regapic', () => {
107107
});
108108
});
109109

110-
it('should support enum conversion in proto message response', done => {
111-
const requestObject = {name: 'shelves/shelf-name'};
112-
const responseObject = {
113-
name: 'shelf-name',
114-
theme: 'shelf-theme',
115-
type: 1,
116-
};
117-
// incomplete types for nodeFetch, so...
118-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
119-
sinon.stub(nodeFetch, 'Promise' as any).returns(
120-
Promise.resolve({
121-
ok: true,
122-
arrayBuffer: () => {
123-
return Promise.resolve(Buffer.from(JSON.stringify(responseObject)));
124-
},
125-
})
126-
);
110+
describe('should support enum conversion in proto message', () => {
111+
it('should support enum conversion in proto message response', done => {
112+
const requestObject = {name: 'shelves/shelf-name'};
113+
const responseObject = {
114+
name: 'shelf-name',
115+
theme: 'shelf-theme',
116+
type: 1,
117+
};
118+
// incomplete types for nodeFetch, so...
119+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
120+
sinon.stub(nodeFetch, 'Promise' as any).returns(
121+
Promise.resolve({
122+
ok: true,
123+
arrayBuffer: () => {
124+
return Promise.resolve(Buffer.from(JSON.stringify(responseObject)));
125+
},
126+
})
127+
);
128+
129+
gaxGrpc.createStub(libraryService, stubOptions).then(libStub => {
130+
libStub.getShelf(
131+
requestObject,
132+
{},
133+
{},
134+
(err: {}, result: {name: {}; theme: {}; type: {}}) => {
135+
assert.strictEqual(err, null);
136+
assert.strictEqual('shelf-name', result.name);
137+
assert.strictEqual('TYPEONE', result.type);
138+
done();
139+
}
140+
);
141+
});
142+
});
127143

128-
gaxGrpc.createStub(libraryService, stubOptions).then(libStub => {
129-
libStub.getShelf(
130-
requestObject,
131-
{},
132-
{},
133-
(err: {}, result: {name: {}; theme: {}; type: {}}) => {
144+
it('should support enum conversion in proto message request using symbolic name', done => {
145+
const shelf = {
146+
name: 'shelf-name',
147+
theme: 'shelf-theme',
148+
type: 'TYPEONE',
149+
};
150+
const requestObject = {shelf: shelf};
151+
// incomplete types for nodeFetch, so...
152+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
153+
sinon.stub(nodeFetch, 'Promise' as any).returns(
154+
Promise.resolve({
155+
ok: true,
156+
arrayBuffer: () => {
157+
return Promise.resolve(Buffer.from(JSON.stringify(shelf)));
158+
},
159+
})
160+
);
161+
gaxGrpc.createStub(libraryService, stubOptions).then(libStub => {
162+
libStub.createShelf(requestObject, {}, {}, (err: {}) => {
134163
assert.strictEqual(err, null);
135-
assert.strictEqual('shelf-name', result.name);
136-
assert.strictEqual('TYPEONE', result.type);
137164
done();
138-
}
165+
});
166+
});
167+
});
168+
169+
it('should support enum conversion in proto message request using type value', done => {
170+
const shelf = {
171+
name: 'shelf-name',
172+
theme: 'shelf-theme',
173+
type: 1,
174+
};
175+
const requestObject = {shelf: shelf};
176+
// incomplete types for nodeFetch, so...
177+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
178+
sinon.stub(nodeFetch, 'Promise' as any).returns(
179+
Promise.resolve({
180+
ok: true,
181+
arrayBuffer: () => {
182+
return Promise.resolve(Buffer.from(JSON.stringify(shelf)));
183+
},
184+
})
139185
);
186+
gaxGrpc.createStub(libraryService, stubOptions).then(libStub => {
187+
libStub.createShelf(requestObject, {}, {}, (err: {}) => {
188+
assert.strictEqual(err, null);
189+
done();
190+
});
191+
});
140192
});
141193
});
142194

0 commit comments

Comments
 (0)