Skip to content

Commit

Permalink
fix(tests): Workaround "quota exceeded" errors from YouTube API (#374)
Browse files Browse the repository at this point in the history
Use MP3 and Soundcloud tracks instead YouTube, to avoid quota exceeded errors from YouTube API, when running Cypress E2E/acceptance tests. Also upgrade to PlayemJS v1.0.0 to see actual error messages from YouTube API.
  • Loading branch information
adrienjoly committed Nov 1, 2020
1 parent 9ce65ac commit 53807af
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 21 deletions.
34 changes: 21 additions & 13 deletions cypress/integration/acceptance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,23 @@ context('Openwhyd', () => {
cy.loginAsAdmin();
cy.visit('/');

// should recognize a track when pasting a Youtube URL in the search box
cy.get('#q').type('https://www.youtube.com/watch?v=aZT8VlTV1YY');
cy.get('#searchResults').contains('Demo');

// should lead to a track page when clicking on the Youtube search result
// should recognize a track when pasting the URL of a MP3 file in the search box
const track = ((url) => ({
url,
name: url.split('/').pop(),
eId: '/fi/' + encodeURIComponent(url),
}))(
'https://ia802508.us.archive.org/5/items/testmp3testfile/mpthreetest.mp3'
);
cy.get('#q').type(track.url);
cy.get('#searchResults').contains(track.name);

// should lead to a track page when clicking on the search result
cy.get('#searchResults li a').first().click();
cy.url().should('include', '/yt/aZT8VlTV1YY');
cy.url().should('include', track.eId);

// should display the name of the track
cy.get('a.btnRepost[href*="Openwhyd Demo (formerly"]').should('exist');
cy.get(`a.btnRepost[href*="${track.name}"]`).should('exist');

// should open a dialog after clicking on the "Add to" button
cy.contains('Add to').click(); //$('a.btnRepost').click();
Expand All @@ -46,10 +53,10 @@ context('Openwhyd', () => {
// should show the post on the user's profile after clicking the link
cy.get('a').contains('your tracks').click();
cy.url().should('include', '/u/');
cy.get('.post a[data-eid="/yt/aZT8VlTV1YY"]').should('be.visible');
cy.get(`.post a.thumb[href^="${track.url}"]`).should('be.visible');

// should open the playbar after the user clicks on the post
cy.get('.post a[data-eid="/yt/aZT8VlTV1YY"]').click();
cy.get(`.post a.thumb[href^="${track.url}"]`).click();
cy.get('#btnPlay').should('be.visible');

// should play the track
Expand Down Expand Up @@ -171,12 +178,13 @@ context('Openwhyd', () => {
});

it('should allow users to search external tracks', function () {
// should find a youtube track with id that starts with underscore
cy.visit('/');
cy.get('#q').click().type('http://www.youtube.com/watch?v=_BU841qpQsI');
const searchResult = `a[onclick="window.goToPage('/yt/_BU841qpQsI');return false;"]`;
cy.get('#q')
.click()
.type('https://soundcloud.com/harissaquartet/no-service');
const searchResult = `a[onclick="window.goToPage('/sc/harissaquartet/no-service');return false;"]`;
cy.get(searchResult)
.should('be.visible')
.should('have.text', 'Los Van Van - Llegada'); // an empty string would mean that no metadata was fetched, caused to https://github.com/openwhyd/openwhyd/issues/102
.should('have.text', 'Harissa - No Service');
});
});
3 changes: 2 additions & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ Cypress.Commands.add('loginAsAdmin', () => {
Cypress.Commands.add('postDummyTracks', (count) => {
const makeTrack = (i) => ({
name: `Fake track #${i}`,
eId: '/yt/Wch3gJG2GJ4', //1-second video, from YouTube
eId:
'/fi/https://ia802508.us.archive.org/5/items/testmp3testfile/mpthreetest.mp3',
img: '/images/cover-track.png',
});
for (let i = 0; i < count; ++i) {
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"mongodb": "^2.2.33",
"iconv": ">=3.0.0",
"object-sizeof": "^1.6.1",
"playemjs": "1.0.0-rc.2",
"playemjs": "1.0.0",
"q-set": "^2.0.8",
"request": "2.88.2"
},
Expand Down
4 changes: 3 additions & 1 deletion public/js/playem-all.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* playemjs 1.0.0-rc.2, commit: 663eb200b5f688025fa0d188394969917f6af210 */
/* playemjs 1.0.0, commit: f0fc497fb2bdca23fd3a6095e320d1529efaea6d */

// configuration

Expand Down Expand Up @@ -2179,6 +2179,7 @@ function YoutubePlayer(){
type : "video",
maxResults : limit,
}).execute(function(res){
if (res.error) throw res.error; // e.g. 403 / "quota exceeded" error
results = res.items.map(translateResult);
cb(results);
});
Expand All @@ -2188,6 +2189,7 @@ function YoutubePlayer(){
'id': query,
'part': 'snippet,contentDetails,statistics'
}).execute(function(res){
if (res.error) throw res.error; // e.g. 403 / "quota exceeded" error
results = res.items.map(translateResult);
cb(results);
});
Expand Down
4 changes: 2 additions & 2 deletions public/js/playem-min.js

Large diffs are not rendered by default.

0 comments on commit 53807af

Please sign in to comment.