Skip to content

Commit

Permalink
docs(samples): Talent API Sample Revision & Test (#1546)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Cervino authored and JustinBeckwith committed Jan 30, 2019
1 parent ef3da37 commit d1bf1b2
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -122,7 +122,7 @@ The are three primary ways to authenticate to Google APIs. Some service support
To learn more about the authentication client, see the [Google Auth Library](https://github.com/googleapis/google-auth-library-nodejs).

### OAuth2 client
This client comes with an [OAuth2][oauth] client that allows you to retrieve an access token and refreshes the token and retry the request seamlessly The basics of Google's OAuth2 implementation is explained on [Google Authorization and Authentication documentation][authdocs].
This client comes with an [OAuth2][oauth] client that allows you to retrieve an access token, refresh it, and retry the request seamlessly. The basics of Google's OAuth2 implementation is explained on [Google Authorization and Authentication documentation][authdocs].

In the following examples, you may need a `CLIENT_ID`, `CLIENT_SECRET` and `REDIRECT_URL`. You can find these pieces of information by going to the [Developer Console][devconsole], clicking your project --> APIs & auth --> credentials.

Expand Down
53 changes: 53 additions & 0 deletions samples/jobs/jobs.js
@@ -0,0 +1,53 @@
// Copyright 2016, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const {google} = require('googleapis');
const sampleClient = require('../sampleclient');

const jobService = google.jobs({
version: 'v3',
auth: sampleClient.oAuth2Client,
});

async function runSample() {
const projectId = await google.auth.getProjectId();
const res = await jobService.projects.companies.create({
parent: `project/${projectId}`,
requestBody: {
company: {
displayName: 'ABC co.',
externalId: '12345',
},
},
});
console.log(res.data);
return res.data;
}

if (module === require.main) {
const scopes = [
'https://www.googleapis.com/auth/jobs',
'https://www.googleapis.com/auth/cloud-platform',
];
sampleClient
.authenticate(scopes)
.then(runSample)
.catch(console.error);
}

module.exports = {
runSample,
client: sampleClient.oAuth2Client,
};
4 changes: 4 additions & 0 deletions src/apis/jobs/README.md
Expand Up @@ -33,6 +33,10 @@ const { jobs, auth } = Jobs;
</script>
```

## v3 Samples

You can find samples of v3 of the Talent Solution API [here](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/jobs/v3)

## License
This library is licensed under Apache 2.0. Full license text is available in [LICENSE](https://github.com/googleapis/google-api-nodejs-client/blob/master/LICENSE).

Expand Down
45 changes: 45 additions & 0 deletions test/samples/test.samples.jobs.ts
@@ -0,0 +1,45 @@
// Copyright 2018, Google, LLC.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import * as assert from 'assert';
import * as nock from 'nock';
import {Utils} from '../utils';

nock.disableNetConnect();

// tslint:disable: no-any
const samples: any = {
jobs: require('../../../samples/jobs/jobs.js'),
};

for (const p in samples) {
if (samples[p]) {
samples.jobs.client.credentials = {access_token: 'not-a-token'};
}
}

describe.skip('Talent API Samples', () => {
afterEach(() => {
nock.cleanAll();
});

it('should create a company', async () => {
const scope =
nock(Utils.baseUrl)
.post(`/v3/jobs/project/${process.env.GCLOUD_PROJECT}/companies`)
.reply(200, {});
const data = await samples.jobs.runSample();
assert(data);
scope.done();
});
});

0 comments on commit d1bf1b2

Please sign in to comment.