Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Verify Accessibility Support in Channel Sidebar Navigation', () => {
beforeEach(() => {
// # Login as test user and visit the off-topic channel
cy.apiLogin(testUser);
cy.apiSaveSidebarSettingPreference();
(cy as any).apiSaveSidebarSettingPreference();
cy.visit(offTopicUrl);
cy.get('#postListContent').should('be.visible');
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

const axios = require('axios');
import axios, {AxiosError, Method} from 'axios';

const timeouts = require('../fixtures/timeouts');
import * as timeouts from '../fixtures/timeouts';

module.exports = async ({baseUrl, user, method = 'get', path, data = {}}) => {
export interface ExternalRequestUser{
username: string;
password: string;
}
interface ExternalRequestArg {
baseUrl: string;
user: ExternalRequestUser;
method: Method;
path: string;
data: any;
}
type ExternalRequestResult = { status: number; statusText: string; data: any; isError?: boolean } | { data: { id: string; isTimeout: boolean }; status?: undefined; statusText?: undefined; isError?: undefined };
export default async function externalRequest(arg: ExternalRequestArg): Promise<ExternalRequestResult> {
const {baseUrl, user, method = 'get', path, data = {}} = arg;
const loginUrl = `${baseUrl}/api/v4/users/login`;

// First we need to login with our external user to get cookies/tokens
Expand All @@ -20,7 +33,7 @@ module.exports = async ({baseUrl, user, method = 'get', path, data = {}}) => {
});

const setCookie = response.headers['set-cookie'];
setCookie.forEach((cookie) => {
(setCookie as any).forEach((cookie: string) => {
Comment on lines 35 to +36
Copy link
Copy Markdown
Contributor

@joebigboi joebigboi Aug 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be const setCookie: string[] = response.headers['set-cookie']; and then you can write setCookie.forEach((cookie) => {

const nameAndValue = cookie.split(';')[0];
cookieString += nameAndValue + ';';
});
Expand Down Expand Up @@ -50,9 +63,9 @@ module.exports = async ({baseUrl, user, method = 'get', path, data = {}}) => {
// If we have a response for the error, pull out the relevant parts
return getErrorResponse(error);
}
};
}

function getErrorResponse(error) {
function getErrorResponse(error: AxiosError) {
if (error.response) {
return {
status: error.response.status,
Expand Down
2 changes: 1 addition & 1 deletion e2e/cypress/tests/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {
dbGetUserSession,
dbUpdateUserSession,
} = require('./db_request');
const externalRequest = require('./external_request');
const externalRequest = require('./external_request').default;
const {fileExist, writeToFile} = require('./file_util');
const getPdfContent = require('./get_pdf_content');
const getRecentEmail = require('./get_recent_email');
Expand Down
2 changes: 1 addition & 1 deletion e2e/cypress/tests/support/api/channel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ declare namespace Cypress {
type?: string,
purpose?: string,
header?: string
): Chainable<Channel>;
): Chainable<{channel: Channel}>;

/**
* Create a new direct message channel between two users.
Expand Down
2 changes: 1 addition & 1 deletion e2e/cypress/tests/support/api/user.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ declare namespace Cypress {
* @example
* cy.apiCreateUser(options);
*/
apiCreateUser(options: Record<string, any>): Chainable<UserProfile>;
apiCreateUser(options: Record<string, any>): Chainable<{user: UserProfile}>;

/**
* Create a new guest user with an options to set name prefix and be able to bypass tutorial steps.
Expand Down
Loading