Skip to content

Commit 8c31358

Browse files
fix: update returned Job with API-determined location in getMetadata (#900)
1 parent a099bf0 commit 8c31358

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/job.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,7 @@ class Job extends Operation {
126126
options?: QueryResultsOptions
127127
) => ResourceStream<RowMetadata>;
128128
constructor(bigQuery: BigQuery, id: string, options?: JobOptions) {
129-
let location;
130-
if (options && options.location) {
131-
location = options.location;
132-
}
129+
let location: string;
133130

134131
const methods = {
135132
/**
@@ -222,7 +219,11 @@ class Job extends Operation {
222219
*/
223220
getMetadata: {
224221
reqOpts: {
225-
qs: {location},
222+
qs: {
223+
get location() {
224+
return location;
225+
},
226+
},
226227
},
227228
},
228229
};
@@ -234,6 +235,15 @@ class Job extends Operation {
234235
methods,
235236
});
236237

238+
Object.defineProperty(this, 'location', {
239+
get() {
240+
return location;
241+
},
242+
set(_location) {
243+
location = _location;
244+
},
245+
});
246+
237247
this.bigQuery = bigQuery;
238248

239249
if (options && options.location) {

test/job.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@ describe('BigQuery/Job', () => {
150150
},
151151
});
152152
});
153+
154+
it('should update the location after initializing job object', () => {
155+
const job = new Job(BIGQUERY, JOB_ID);
156+
job.location = LOCATION;
157+
const calledWith = job.calledWith_[0];
158+
159+
assert.deepStrictEqual(calledWith.methods.getMetadata, {
160+
reqOpts: {
161+
qs: {location: LOCATION},
162+
},
163+
});
164+
});
153165
});
154166

155167
describe('cancel', () => {

0 commit comments

Comments
 (0)