Skip to content

Commit

Permalink
seed data fixed. cypress tests for elastic search added
Browse files Browse the repository at this point in the history
  • Loading branch information
mbareeva committed Aug 15, 2021
1 parent cc318f4 commit 805be4b
Show file tree
Hide file tree
Showing 7 changed files with 599 additions and 63 deletions.
83 changes: 83 additions & 0 deletions cypress/integration/backend/elasticsearch.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

const { Context } = require("mocha");
const bonsai = process.env.BONSAI_URL || 'http://localhost:9200';
import data from '../../fixtures/mock_data.json';

// **** METHODS **** //
context('Elasticsearch testing', () => {
describe('Basics', () => {
it('checks whether the cluster is running', () => {
cy.request(bonsai)
.then((response) => {
expect(response).property('status').to.equal(200)
expect(response).property('body').to.have.property('cluster_name')
})
})
it("searches all the available users", () => {
cy.request(bonsai + '/users/_search')
.then((response) => {
expect(response).property('status').to.equal(200)
expect(response.body.hits.total).property('value').to.not.eq(0)
})
})
it("searches all the availabale media items", () => {
cy.request(bonsai + '/medias/_search')
.then((response) => {
expect(response).property('status').to.equal(200)
expect(response.body.hits.total).property('value').to.not.eq(0)
})
})
it("searches for specialisation & shows the results", () => {
cy.request({
method: 'GET',
url: bonsai + '/users/_search',
body: { query: { match: { specialisation: "Athlete" } } }
}).then((response) => {
expect(response).property('status').to.equal(200)
expect(response.body.hits.total).property('value').to.not.eq(0)
})
})
it("shows no results for the specialisation search", () => {
cy.request({
method: 'GET',
url: bonsai + '/users/_search',
body: { query: { match: { specialisation: "Doctor" } } }
}).then((response) => {
expect(response).property('status').to.equal(200)
expect(response.body.hits.total).property('value').to.eq(0)
})
})

it("shows results of a term search in captions", () => {
cy.request({
method: 'GET',
url: bonsai + '/medias/_search',
body: { query: { match: { caption: "gym" } } }
}).then((response) => {
expect(response).property('status').to.equal(200)
expect(response.body.hits.total).property('value').to.not.eq(0)
})
})

it("shows results of a multi-match search for captions", () => {
cy.request({
method: 'GET',
url: bonsai + '/users/_search',
body: {
query: {
multi_match: {
query: data.user.latestMedia[0].caption,
//type: "best_fields",
fields: ["latestMedia.caption", "biography"]
}
}
}
}).then((response) => {
expect(response).property('status').to.equal(200)
expect(response.body.hits.total).property('value').to.not.eq(0)
})
})


})
})
22 changes: 22 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
25 changes: 25 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
Loading

0 comments on commit 805be4b

Please sign in to comment.