Skip to content

Commit c6f3449

Browse files
Merge pull request #153 from sspenst/fix-user-tests
fix: refresh token for user tests
2 parents 3a641b2 + ad72ea2 commit c6f3449

File tree

12 files changed

+65
-1028
lines changed

12 files changed

+65
-1028
lines changed

.env.template

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1+
INTEGRATION_TESTS_REFRESH_TOKEN=your_refresh_token_for_tests
12
INTEGRATION_TESTS_SPOTIFY_CLIENT_ID=your_spotify_client_id_for_tests
23
INTEGRATION_TESTS_SPOTIFY_CLIENT_SECRET=your_spotify_client_secret_for_tests
3-
INTEGRATION_TESTS_USER_EMAIL=some@validuser.co.uk
4-
INTEGRATION_TESTS_USER_PASSWORD=some-valid-password
54
VITE_SPOTIFY_CLIENT_ID=your_spotify_client_id_for_tests
65
VITE_REDIRECT_TARGET=http://localhost:3000

CONTRIBUTING.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ You will need to create a new app in the Spotify Developer portal, and add a red
3535

3636
Add the following environment variables:
3737

38+
- `INTEGRATION_TESTS_REFRESH_TOKEN`
3839
- `INTEGRATION_TESTS_SPOTIFY_CLIENT_ID`
3940
- `INTEGRATION_TESTS_SPOTIFY_CLIENT_SECRET`
40-
- `INTEGRATION_TESTS_USER_EMAIL`
41-
- `INTEGRATION_TESTS_USER_PASSWORD`
4241

43-
The latter two credentials are used to run integration tests in the scope of a *real user account*. This is required to test endpoints that require a user's authorization, such as `followPlaylist`. You need to make sure that your user has access to whichever Spotify app your client credentials and secret are for.
42+
`INTEGRATION_TESTS_REFRESH_TOKEN` is used to run integration tests in the scope of a *real user account*. This is required to test endpoints that require a user's authorization, such as `followPlaylist`. You need to make sure that your user has access to whichever Spotify app your client credentials and secret are for. You can obtain a refresh token by running the example app and authenticating.
4443

4544
You can run the tests with `npm run test`, or using a plugin like [Wallaby](https://wallabyjs.com/).
4645

@@ -76,12 +75,11 @@ You will need to create a new app in the Spotify Developer portal, and add a red
7675

7776
You will need to add the following environment variables:
7877

78+
- `INTEGRATION_TESTS_REFRESH_TOKEN`
7979
- `INTEGRATION_TESTS_SPOTIFY_CLIENT_ID`
8080
- `INTEGRATION_TESTS_SPOTIFY_CLIENT_SECRET`
81-
- `INTEGRATION_TESTS_USER_EMAIL`
82-
- `INTEGRATION_TESTS_USER_PASSWORD`
8381

84-
The latter two credentials are used to run integration tests in the scope of a *real user account*. This is required to test endpoints that require a user's authorization, such as `followPlaylist`. You need to make sure that your user has access to whichever Spotify app your client credentials and secret are for.
82+
`INTEGRATION_TESTS_REFRESH_TOKEN` is used to run integration tests in the scope of a *real user account*. This is required to test endpoints that require a user's authorization, such as `followPlaylist`. You need to make sure that your user has access to whichever Spotify app your client credentials and secret are for. You can obtain a refresh token by running the example app and authenticating.
8583

8684
You can run the tests with `npm run test`, or using a plugin like [Wallaby](https://wallabyjs.com/).
8785

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,11 @@ You will need to create a new app in the Spotify Developer portal, and add a red
293293

294294
You will need to add the following environment variables:
295295

296+
- `INTEGRATION_TESTS_REFRESH_TOKEN`
296297
- `INTEGRATION_TESTS_SPOTIFY_CLIENT_ID`
297298
- `INTEGRATION_TESTS_SPOTIFY_CLIENT_SECRET`
298-
- `INTEGRATION_TESTS_USER_EMAIL`
299-
- `INTEGRATION_TESTS_USER_PASSWORD`
300299

301-
The latter two credentials are used to run integration tests in the scope of a *real user account*. This is required to test endpoints that require a user's authorization, such as `followPlaylist`. You need to make sure that your user has access to whichever Spotify app your client credentials and secret are for.
300+
`INTEGRATION_TESTS_REFRESH_TOKEN` is used to run integration tests in the scope of a *real user account*. This is required to test endpoints that require a user's authorization, such as `followPlaylist`. You need to make sure that your user has access to whichever Spotify app your client credentials and secret are for. You can obtain a refresh token by running the example app and authenticating.
302301

303302
You can run the tests with `npm run test`, or using a plugin like [Wallaby](https://wallabyjs.com/).
304303

example/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ <h2>Logged in as <span id="displayName"></span></h2>
2020
<li>Spotify URI: <a id="uri" href="#"></a></li>
2121
<li>Link: <a id="url" href="#"></a></li>
2222
<li>Profile Image: <span id="imgUrl"></span></li>
23+
<li>Refresh Token: <span id="refreshToken"></span></li>
2324
</ul>
2425
</section>
2526

example/script.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ document.getElementById("uri")!.setAttribute("href", profile.external_urls.spoti
2424
document.getElementById("url")!.innerText = profile.href;
2525
document.getElementById("url")!.setAttribute("href", profile.href);
2626
document.getElementById("imgUrl")!.innerText = profile.images[0]?.url ?? '(no profile image)';
27+
28+
const accessToken = await authStrategy.getAccessToken();
29+
document.getElementById("refreshToken")!.innerText = accessToken?.refresh_token ?? '(no refresh token)';

example/tsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"module": "ESNext",
5+
"lib": ["ES2020", "DOM"],
6+
"moduleResolution": "bundler",
7+
"skipLibCheck": true,
8+
"strict": true,
9+
"esModuleInterop": true,
10+
"forceConsistentCasingInFileNames": true
11+
},
12+
"include": ["**/*.ts", "env.d.ts"]
13+
}
14+

0 commit comments

Comments
 (0)