Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(transaction): accept json options in run/runStream #446

Merged
merged 1 commit into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,10 @@ class Transaction extends TransactionRequest {
transaction: {},
},
codec.encodeQuery(query));

delete reqOpts.json;
delete reqOpts.jsonOptions;

if (this.id) {
reqOpts.transaction.id = this.id;
} else {
Expand All @@ -728,7 +732,10 @@ class Transaction extends TransactionRequest {
reqOpts: extend({}, reqOpts, {resumeToken}),
});
};
return partialResultStream(makeRequest);
return partialResultStream(makeRequest, {
json: query.json,
jsonOptions: query.jsonOptions,
});
}
/**
* @typedef {array} RunUpdateResponse
Expand Down
23 changes: 23 additions & 0 deletions test/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,29 @@ describe('Transaction', () => {
const makeRequestFn = stream.calledWith_[0];
makeRequestFn(resumeToken);
});

it('should not pass json options to the request', done => {
const query = extend({json: true, jsonOptions: {}}, QUERY);

transaction.requestStream = (options) => {
assert.strictEqual(options.reqOpts.json, undefined);
assert.strictEqual(options.reqOpts.jsonOptions, undefined);
done();
};

const stream = transaction.runStream(query);
const makeRequestFn = stream.calledWith_[0];
makeRequestFn();
});

it('should pass the json options', () => {
const expectedJsonOptions = {json: true, jsonOptions: {a: 'b'}};
const query = extend({}, expectedJsonOptions, QUERY);
const stream = transaction.runStream(query);
const options = stream.calledWith_[1];

assert.deepStrictEqual(options, expectedJsonOptions);
});
});

describe('runUpdate', () => {
Expand Down