blob: 7c6d944a819f458e005a9c807e86bf9b98d12603 [file]
<!DOCTYPE html>
<!--
Copyright 2017 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>cr-buildbucket-client tests</title>
<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<script src="../node_modules/web-component-tester/browser.js"></script>
<script type="module">
import '../src/main/resources/static/cache-object.js';
import {
assertRejects,
deepFreeze,
} from './test-util.js';
import {
BuildbucketV2Client,
BuildStatus,
retry,
} from '../src/main/resources/static/buildbucket-client.js';
suite('BuildbucketV2Client tests', () => {
let sandbox;
let client;
setup(() => {
sandbox = sinon.sandbox.create();
client = new BuildbucketV2Client('buildbucket.example.com');
client._getAccessToken = async () => 'accessToken';
});
teardown(() => {
sandbox.restore();
});
test('batch makes POST request to buildbucket v2 API', async () => {
const expected = {
builds: [],
};
sandbox.stub(window, 'fetch').returns(Promise.resolve({
ok: true,
text: async () => `)]}'${JSON.stringify(expected)}`,
}));
const req = {
searchBuilds: {
predicate: {
builder: {
project: 'chromium',
},
},
},
};
const actual = await client.batch(req);
assert.deepEqual(actual, expected);
assert.isTrue(fetch.alwaysCalledWithExactly(
'https://buildbucket.example.com/prpc/buildbucket.v2.Builds/Batch', {
method: 'POST',
headers: {
'accept': 'application/json',
'content-type': 'application/json',
'authorization': 'Bearer accessToken',
},
body: JSON.stringify(req),
signal: undefined,
}
));
});
});
</script>