Skip to content

Instantly share code, notes, and snippets.

@gcirone
Last active November 22, 2018 14:03
Show Gist options
  • Save gcirone/ca5272990c8f81c3e3e41f58d74f33c9 to your computer and use it in GitHub Desktop.
Save gcirone/ca5272990c8f81c3e3e41f58d74f33c9 to your computer and use it in GitHub Desktop.
/// <reference types="cypress" />
const sportsUrl = '/sports';
describe('WebSocket Integration Test', () => {
let webSocketStub: any;
before(() => setupRoutesAndFixtures());
describe('When access to the Sports homepage', () => {
before(() => {
cy.setCookie('LANG', 'en');
webSocketStub = { send : cy.spy().as('WebSocketMessage'), close: cy.spy() };
const onBeforeLoad = win => cy.stub(win as any, 'WebSocket')
.as('WebSocket').returns(webSocketStub);
cy.visit(sportsUrl, { onBeforeLoad });
cy.wait('@ScoreApi').then(() => webSocketStub.onopen());
});
it('Should receive COMPETITION update correctly', function () {
webSocketStub.onmessage({ data: this.eventCompetition });
getCouponAt(0)
.find('.league-header')
.contains('Copa Libertadores');
});
it('Should receive PRICE update correctly', function () {
webSocketStub.onmessage({ data: this.eventOutcome });
getCouponAt(1)
.find('.market-type:nth-of-type(3) li:nth-child(3) .bet-btn')
.should('have.class', 'price-increased')
.contains('7.00');
});
});
function getCouponAt(index: number) {
return cy.get('sp-coupon').eq(index);
}
function setupRoutesAndFixtures() {
cy.server();
cy.route('**/sports/config/site', 'fixture:site/sports-config-site');
cy.route('**/sports.json', 'fixture:site/sports-navigation');
cy.route('**/v2/nav/A/description?lang=en', 'fixture:site/sports-nav-api');
cy.route('**/slugs/sports-homepage-carousel', {});
cy.route(/(event\/v2\/events\/A\/description).*(liveOnly)/, 'fixture:sports-home-live');
cy.route(/(event\/v2\/events\/A\/description).*(preMatchOnly)/, 'fixture:sports-home-prematch');
cy.route('**/scores/3672794+3672791+3672781', []).as('ScoreApi');
cy.route('**/scores/3672780', []);
cy.fixture('updates/event-outcome').as('eventOutcome');
cy.fixture('updates/event-competition').as('eventCompetition');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment