Skip to content

Commit

Permalink
Rename files and vars to use camel case inline with the naming conven…
Browse files Browse the repository at this point in the history
…tion (#1048)

Co-authored-by: Ansible-lightspeed-Bot <ansible_lightspeed_bot@redhat.com>
  • Loading branch information
ganeshrn and Ansible-lightspeed-Bot authored Jan 17, 2024
1 parent bcc4fae commit 33cb5de
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/features/lightspeed/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { LightSpeedAuthenticationProvider } from "./lightSpeedOAuthProvider";
import { getBaseUri } from "./utils/webUtils";
import { ANSIBLE_LIGHTSPEED_API_TIMEOUT } from "../../definitions/constants";
import { retrieve_error } from "./handle_api_error";
import { retrieveError } from "./handleApiError";

export class LightSpeedAPI {
private axiosInstance: AxiosInstance | undefined;
Expand Down Expand Up @@ -113,7 +113,7 @@ export class LightSpeedAPI {
return response.data;
} catch (error) {
const err = error as AxiosError;
vscode.window.showErrorMessage(retrieve_error(err));
vscode.window.showErrorMessage(retrieveError(err));
this._completionRequestInProgress = false;
return {} as CompletionResponseParams;
} finally {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AxiosError } from "axios";

export function retrieve_error(err: AxiosError): string {
export function retrieveError(err: AxiosError): string {
if (err && "response" in err) {
if (err?.response?.status === 401) {
return "User not authorized to access Ansible Lightspeed.";
Expand Down
30 changes: 15 additions & 15 deletions test/units/lightspeed/contentmatches.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {
ISuggestionDetails,
} from "../../../src/interfaces/lightspeed";

function create_match_response(): ContentMatchesResponseParams {
const content_match_params = {
function createMatchResponse(): ContentMatchesResponseParams {
const contentMatchParams = {
repo_name: "ansible.ansible",
repo_url: "https://github.com/ansible/ansible",
path: "some/file.py",
Expand All @@ -32,13 +32,13 @@ function create_match_response(): ContentMatchesResponseParams {
score: 123,
} as IContentMatchParams;
const icontent_match = {
contentmatch: [content_match_params],
contentmatch: [contentMatchParams],
} as IContentMatch;

return { contentmatches: [icontent_match] } as ContentMatchesResponseParams;
}

function create_content_matches_webview(): ContentMatchesWebview {
function createContentMatchesWebview(): ContentMatchesWebview {
const m_context: Partial<ExtensionContext> = {};
const m_client: Partial<LanguageClient> = {};
const m_settings: Partial<SettingsManager> = {};
Expand All @@ -58,12 +58,12 @@ function create_content_matches_webview(): ContentMatchesWebview {

describe("ContentMatches view", () => {
it("with normal input", async function () {
const cmw = create_content_matches_webview();
const cmw = createContentMatchesWebview();
cmw.apiInstance.contentMatchesRequest = async (
inputData: ContentMatchesRequestParams
): Promise<ContentMatchesResponseParams> => {
assert.equal(inputData.model, undefined);
return create_match_response();
return createMatchResponse();
};
const res = await cmw.requestInlineSuggestContentMatches("foo", "bar");
assert.equal(
Expand All @@ -73,13 +73,13 @@ describe("ContentMatches view", () => {
});

it("with a specific model", async function () {
const cmw = create_content_matches_webview();
const cmw = createContentMatchesWebview();
cmw.settingsManager.settings.lightSpeedService.model = "the_model";
cmw.apiInstance.contentMatchesRequest = async (
inputData: ContentMatchesRequestParams
): Promise<ContentMatchesResponseParams> => {
assert.equal(inputData.model, "the_model");
return create_match_response();
return createMatchResponse();
};
const res = await cmw.requestInlineSuggestContentMatches("foo", "bar");
assert.equal(
Expand All @@ -91,13 +91,13 @@ describe("ContentMatches view", () => {

describe("GetWebviewContent", () => {
it("no suggestion", async function () {
const cmw = create_content_matches_webview();
const cmw = createContentMatchesWebview();
const res = await cmw["getWebviewContent"]();
assert.match(res, new RegExp("No training matches found"));
});

it("suggestion has no matches", async function () {
const cmw = create_content_matches_webview();
const cmw = createContentMatchesWebview();
cmw.suggestionDetails = [
{
suggestion: "- name: foo\n my.mod:\n",
Expand All @@ -107,7 +107,7 @@ describe("GetWebviewContent", () => {
cmw.apiInstance.contentMatchesRequest = async (
inputData: ContentMatchesRequestParams // eslint-disable-line @typescript-eslint/no-unused-vars
): Promise<ContentMatchesResponseParams> => {
const res = create_match_response();
const res = createMatchResponse();
res.contentmatches = [];
return res;
};
Expand All @@ -116,7 +116,7 @@ describe("GetWebviewContent", () => {
});

it("suggest has invalid YAML", async function () {
const cmw = create_content_matches_webview();
const cmw = createContentMatchesWebview();
cmw.suggestionDetails = [
{
suggestion: "- name: foo\nI\n\nBROKEN\n",
Expand All @@ -126,7 +126,7 @@ describe("GetWebviewContent", () => {
cmw.apiInstance.contentMatchesRequest = async (
inputData: ContentMatchesRequestParams // eslint-disable-line @typescript-eslint/no-unused-vars
): Promise<ContentMatchesResponseParams> => {
return create_match_response();
return createMatchResponse();
};
const spiedConsole = sinon.spy(console, "log");
const res = await cmw["getWebviewContent"]();
Expand All @@ -141,7 +141,7 @@ describe("GetWebviewContent", () => {
});

it("suggestion with a match", async function () {
const cmw = create_content_matches_webview();
const cmw = createContentMatchesWebview();
cmw.suggestionDetails = [
{
suggestion: "- name: foo\n my.mod:\n",
Expand All @@ -151,7 +151,7 @@ describe("GetWebviewContent", () => {
cmw.apiInstance.contentMatchesRequest = async (
inputData: ContentMatchesRequestParams // eslint-disable-line @typescript-eslint/no-unused-vars
): Promise<ContentMatchesResponseParams> => {
return create_match_response();
return createMatchResponse();
};

function setRhUserHasSeat(has_seat: boolean) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require("assert");

import { AxiosError, AxiosHeaders } from "axios";
import { retrieve_error } from "../../../src/features/lightspeed/handle_api_error";
import { retrieveError } from "../../../src/features/lightspeed/handleApiError";
import assert from "assert";

function create_error(http_code: number, data = {}): AxiosError {
function createError(http_code: number, data = {}): AxiosError {
const request = { path: "/wisdom" };
const headers = new AxiosHeaders({
"Access-Control-Allow-Origin": "*",
Expand Down Expand Up @@ -33,48 +33,48 @@ function create_error(http_code: number, data = {}): AxiosError {

describe("testing the error handling", () => {
it("err generic", () => {
const msg = retrieve_error(create_error(200));
const msg = retrieveError(createError(200));
assert.equal(
msg,
"Failed to fetch inline suggestion from Ansible Lightspeed with status code: 200. Try again after some time."
);
});
it("err Unauthorized", () => {
const msg = retrieve_error(create_error(401));
const msg = retrieveError(createError(401));
assert.equal(msg, "User not authorized to access Ansible Lightspeed.");
});
it("err Too Many Requests", () => {
const msg = retrieve_error(create_error(429));
const msg = retrieveError(createError(429));
assert.equal(
msg,
"Too many requests to Ansible Lightspeed. Please try again after some time."
);
});
it("err Bad Request from Cloudflare", () => {
const msg = retrieve_error(
create_error(400, { message: "Some string from Cloudflare." })
const msg = retrieveError(
createError(400, { message: "Some string from Cloudflare." })
);
assert.equal(
msg,
"Cloudflare rejected the request. Please contact your administrator."
);
});
it("err Bad Request", () => {
const msg = retrieve_error(create_error(400));
const msg = retrieveError(createError(400));
assert.equal(msg, "Bad Request response. Please try again.");
});
it("err Forbidden - WCA Model ID is invalid", () => {
const msg = retrieve_error(
create_error(403, { message: "WCA Model ID is invalid" })
const msg = retrieveError(
createError(403, { message: "WCA Model ID is invalid" })
);
assert.equal(
msg,
`Model ID is invalid. Please contact your administrator.`
);
});
it("err Forbidden - No seat", () => {
const msg = retrieve_error(
create_error(403, {
const msg = retrieveError(
createError(403, {
code: "permission_denied__org_ready_user_has_no_seat",
})
);
Expand All @@ -84,8 +84,8 @@ describe("testing the error handling", () => {
);
});
it("err Forbidden - Trial expired", () => {
const msg = retrieve_error(
create_error(403, {
const msg = retrieveError(
createError(403, {
code: "permission_denied__user_trial_expired",
})
);
Expand All @@ -95,8 +95,8 @@ describe("testing the error handling", () => {
);
});
it("err Forbidden - WCA not ready", () => {
const msg = retrieve_error(
create_error(403, {
const msg = retrieveError(
createError(403, {
code: "permission_denied__org_not_ready_because_wca_not_configured",
})
);
Expand All @@ -106,35 +106,35 @@ describe("testing the error handling", () => {
);
});
it("err Forbidden", () => {
const msg = retrieve_error(create_error(403));
const msg = retrieveError(createError(403));
assert.equal(msg, `User not authorized to access Ansible Lightspeed.`);
});
it("err Internal Server Error", () => {
const msg = retrieve_error(create_error(500));
const msg = retrieveError(createError(500));
assert.equal(
msg,
`Ansible Lightspeed encountered an error. Try again after some time.`
);
});
it("err Unexpected Err code", () => {
const msg = retrieve_error(create_error(999));
const msg = retrieveError(createError(999));
assert.equal(
msg,
"Failed to fetch inline suggestion from Ansible Lightspeed with status code: 999. Try again after some time."
);
});
it("err Timeout", () => {
const err = create_error(0);
const err = createError(0);
err.code = AxiosError.ECONNABORTED;
const msg = retrieve_error(err);
const msg = retrieveError(err);
assert.equal(
msg,
"Ansible Lightspeed connection timeout. Try again after some time."
);
});

it("err Unexpected Client error", () => {
const msg = retrieve_error(create_error(0));
const msg = retrieveError(createError(0));
assert.equal(
msg,
"Failed to fetch inline suggestion from Ansible Lightspeed. Try again after some time."
Expand Down

0 comments on commit 33cb5de

Please sign in to comment.