Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
fix: samples and tests updated (#13)
Browse files Browse the repository at this point in the history
* fix: samples and tests updated

Samples fixed and updated to use the correct client library.
Integration test added.

* fix: samples and tests updated

Samples fixed and updated to use the correct client library.
Integration test added.
  • Loading branch information
ikuleshov committed Aug 3, 2020
1 parent 1b2cebf commit 55f4366
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions samples/package.json
Expand Up @@ -3,6 +3,7 @@
"private": true,
"license": "Apache-2.0",
"author": "Google LLC",
"repository": "googleapis/nodejs-analytics-admin",
"engines": {
"node": ">=10"
},
Expand Down
Expand Up @@ -57,7 +57,6 @@ async function main() {
});
}

main().catch(console.error);
main(...process.argv.slice(2)).catch(err => {
console.error(err.message);
process.exitCode = 1;
Expand Down
23 changes: 12 additions & 11 deletions samples/quickstart_installed_oauth2.js
Expand Up @@ -32,13 +32,15 @@ const url = require('url');
const open = require('open');
const destroyer = require('server-destroy');

// Reads the secrets from a `keys.json` file, which should be downloaded from
// the Google Developers Console and saved in the same directory with the sample
// app.
// Reads the secrets from a `oauth2.keys.json` file, which should be downloaded
// from the Google Developers Console and saved in the same directory with the
// sample app.
// eslint-disable-next-line node/no-unpublished-require
// eslint-disable-next-line node/no-missing-require, node/no-unpublished-require
const keys = require('./oauth2.keys.json');

// This sample app only calls read-only methods from the Admin API. Include
// additional scopes if calling methods that modify the configuration.
const SCOPES = ['https://www.googleapis.com/auth/analytics.readonly'];

async function listAccounts(authClient) {
Expand Down Expand Up @@ -73,13 +75,12 @@ function getAuthenticatedClient() {
const oAuth2Client = new OAuth2Client(
keys.web.client_id,
keys.web.client_secret,
// The first redirect URL from the `keys.json` file will be used to
// generate the OAuth2 callback URL. Update the line below or edit the
// redirect URL in the Google Developers Console if needed.
// The first redirect URL from the `oauth2.keys.json` file will be used
// to generate the OAuth2 callback URL. Update the line below or edit
// the redirect URL in the Google Developers Console if needed.
// This sample app expects the callback URL to be
// 'http://localhost:3000/oauth2callback'
//keys.web.redirect_uris[0]
'http://ikuleshov.mtv.corp.google.com:3000/oauth2callback'
keys.web.redirect_uris[0]
);

// Generate the url that will be used for the consent dialog.
Expand All @@ -88,13 +89,14 @@ function getAuthenticatedClient() {
scope: SCOPES.join(' '),
});

// Open an http server to accept the oauth callback. In this simple example, the
// Open an http server to accept the oauth callback. In this example, the
// only request to our webserver is to /oauth2callback?code=<code>
const server = http
.createServer(async (req, res) => {
try {
if (req.url.indexOf('/oauth2callback') > -1) {
// acquire the code from the querystring, and close the web server.
// Acquire the code from the querystring, and close the web
// server.
const qs = new url.URL(req.url, 'http://localhost:3000')
.searchParams;
const code = qs.get('code');
Expand Down Expand Up @@ -129,7 +131,6 @@ async function main() {
getAuthenticatedClient().then(authClient => listAccounts(authClient));
}

main().catch(console.error);
main(...process.argv.slice(2)).catch(err => {
console.error(err.message);
process.exitCode = 1;
Expand Down
15 changes: 15 additions & 0 deletions system-test/analyticsadmin.ts
@@ -0,0 +1,15 @@
import * as assert from 'assert';
import {describe, it} from 'mocha';

import {AnalyticsAdminServiceClient} from '../src';
import {google} from '../protos/protos';

describe('AnalyticsAdmin', () => {
const analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

it('list Google Analytics accounts', async () => {
const request = new google.analytics.admin.v1alpha.ListAccountsRequest();
const [accounts] = await analyticsAdminServiceClient.listAccounts(request);
assert(accounts.length);
});
});

0 comments on commit 55f4366

Please sign in to comment.