|
|
|
|
|
|
|
|
|
export const adminUser = { |
|
name: 'Admin User', |
|
email: '[email protected]', |
|
password: 'password' |
|
}; |
|
|
|
const login = (email: string, password: string) => { |
|
return cy.session( |
|
email, |
|
() => { |
|
|
|
|
|
localStorage.setItem('locale', 'en-US'); |
|
|
|
cy.visit('/auth'); |
|
|
|
cy.get('input[autocomplete="email"]').type(email); |
|
cy.get('input[type="password"]').type(password); |
|
|
|
cy.get('button[type="submit"]').click(); |
|
|
|
cy.get('#chat-search').should('exist'); |
|
|
|
if (localStorage.getItem('version') === null) { |
|
cy.get('button').contains("Okay, Let's Go!").click(); |
|
} |
|
}, |
|
{ |
|
validate: () => { |
|
cy.request({ |
|
method: 'GET', |
|
url: '/api/v1/auths/', |
|
headers: { |
|
Authorization: 'Bearer ' + localStorage.getItem('token') |
|
} |
|
}); |
|
} |
|
} |
|
); |
|
}; |
|
|
|
const register = (name: string, email: string, password: string) => { |
|
return cy |
|
.request({ |
|
method: 'POST', |
|
url: '/api/v1/auths/signup', |
|
body: { |
|
name: name, |
|
email: email, |
|
password: password |
|
}, |
|
failOnStatusCode: false |
|
}) |
|
.then((response) => { |
|
expect(response.status).to.be.oneOf([200, 400]); |
|
}); |
|
}; |
|
|
|
const registerAdmin = () => { |
|
return register(adminUser.name, adminUser.email, adminUser.password); |
|
}; |
|
|
|
const loginAdmin = () => { |
|
return login(adminUser.email, adminUser.password); |
|
}; |
|
|
|
Cypress.Commands.add('login', (email, password) => login(email, password)); |
|
Cypress.Commands.add('register', (name, email, password) => register(name, email, password)); |
|
Cypress.Commands.add('registerAdmin', () => registerAdmin()); |
|
Cypress.Commands.add('loginAdmin', () => loginAdmin()); |
|
|
|
Cypress.Commands.add('uploadTestDocument', (suffix: any) => { |
|
|
|
cy.loginAdmin(); |
|
|
|
cy.visit('/workspace/documents'); |
|
|
|
cy.get("button[aria-label='Add Docs']").click(); |
|
cy.readFile('cypress/data/example-doc.txt').then((text) => { |
|
|
|
cy.get('#upload-doc-input').selectFile( |
|
{ |
|
contents: Cypress.Buffer.from(text + Date.now()), |
|
fileName: `document-test-initial-${suffix}.txt`, |
|
mimeType: 'text/plain', |
|
lastModified: Date.now() |
|
}, |
|
{ |
|
force: true |
|
} |
|
); |
|
|
|
cy.get("button[aria-label='Add Tag']").click(); |
|
cy.get("input[placeholder='Add a tag']").type('cypress-test'); |
|
cy.get("button[aria-label='Save Tag']").click(); |
|
|
|
|
|
cy.get("button[type='submit']").click(); |
|
|
|
|
|
cy.get('button').contains('#cypress-test').should('exist'); |
|
cy.get('div').contains(`document-test-initial-${suffix}.txt`).should('exist'); |
|
}); |
|
}); |
|
|
|
Cypress.Commands.add('deleteTestDocument', (suffix: any) => { |
|
cy.loginAdmin(); |
|
cy.visit('/workspace/documents'); |
|
|
|
cy.get('div') |
|
.contains(`document-test-initial-${suffix}.txt`) |
|
.find("button[aria-label='Delete Doc']") |
|
.click(); |
|
}); |
|
|
|
before(() => { |
|
cy.registerAdmin(); |
|
}); |
|
|