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

Commit 55f4366

Browse files
authored
fix: samples and tests updated (#13)
* 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.
1 parent 1b2cebf commit 55f4366

4 files changed

Lines changed: 28 additions & 12 deletions

File tree

samples/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"private": true,
44
"license": "Apache-2.0",
55
"author": "Google LLC",
6+
"repository": "googleapis/nodejs-analytics-admin",
67
"engines": {
78
"node": ">=10"
89
},
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ async function main() {
5757
});
5858
}
5959

60-
main().catch(console.error);
6160
main(...process.argv.slice(2)).catch(err => {
6261
console.error(err.message);
6362
process.exitCode = 1;

samples/quickstart_installed_oauth2.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ const url = require('url');
3232
const open = require('open');
3333
const destroyer = require('server-destroy');
3434

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

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

4446
async function listAccounts(authClient) {
@@ -73,13 +75,12 @@ function getAuthenticatedClient() {
7375
const oAuth2Client = new OAuth2Client(
7476
keys.web.client_id,
7577
keys.web.client_secret,
76-
// The first redirect URL from the `keys.json` file will be used to
77-
// generate the OAuth2 callback URL. Update the line below or edit the
78-
// redirect URL in the Google Developers Console if needed.
78+
// The first redirect URL from the `oauth2.keys.json` file will be used
79+
// to generate the OAuth2 callback URL. Update the line below or edit
80+
// the redirect URL in the Google Developers Console if needed.
7981
// This sample app expects the callback URL to be
8082
// 'http://localhost:3000/oauth2callback'
81-
//keys.web.redirect_uris[0]
82-
'http://ikuleshov.mtv.corp.google.com:3000/oauth2callback'
83+
keys.web.redirect_uris[0]
8384
);
8485

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

91-
// Open an http server to accept the oauth callback. In this simple example, the
92+
// Open an http server to accept the oauth callback. In this example, the
9293
// only request to our webserver is to /oauth2callback?code=<code>
9394
const server = http
9495
.createServer(async (req, res) => {
9596
try {
9697
if (req.url.indexOf('/oauth2callback') > -1) {
97-
// acquire the code from the querystring, and close the web server.
98+
// Acquire the code from the querystring, and close the web
99+
// server.
98100
const qs = new url.URL(req.url, 'http://localhost:3000')
99101
.searchParams;
100102
const code = qs.get('code');
@@ -129,7 +131,6 @@ async function main() {
129131
getAuthenticatedClient().then(authClient => listAccounts(authClient));
130132
}
131133

132-
main().catch(console.error);
133134
main(...process.argv.slice(2)).catch(err => {
134135
console.error(err.message);
135136
process.exitCode = 1;

system-test/analyticsadmin.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as assert from 'assert';
2+
import {describe, it} from 'mocha';
3+
4+
import {AnalyticsAdminServiceClient} from '../src';
5+
import {google} from '../protos/protos';
6+
7+
describe('AnalyticsAdmin', () => {
8+
const analyticsAdminServiceClient = new AnalyticsAdminServiceClient();
9+
10+
it('list Google Analytics accounts', async () => {
11+
const request = new google.analytics.admin.v1alpha.ListAccountsRequest();
12+
const [accounts] = await analyticsAdminServiceClient.listAccounts(request);
13+
assert(accounts.length);
14+
});
15+
});

0 commit comments

Comments
 (0)