Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ import { Response } from "./responses/response"
import { SaslAuthenticateResponse } from "./responses/sasl_authenticate_response"
import { SaslHandshakeResponse } from "./responses/sasl_handshake_response"
import { TuneResponse } from "./responses/tune_response"
import { DEFAULT_FRAME_MAX, DEFAULT_UNLIMITED_FRAME_MAX, REQUIRED_MANAGEMENT_VERSION, removeFrom } from "./util"
import {
DEFAULT_FRAME_MAX,
DEFAULT_UNLIMITED_FRAME_MAX,
REQUIRED_MANAGEMENT_VERSION,
isString,
removeFrom,
} from "./util"
import { Version, checkServerDeclaredVersions, getClientSupportedVersions } from "./versions"
import { WaitingResponse } from "./waiting_response"
import { ClientListenersParams, ClientParams, ClosingParams, QueryOffsetParams, StoreOffsetParams } from "./client"
Expand Down Expand Up @@ -474,7 +480,7 @@ export class Connection {

private async open(params: { virtualHost: string }) {
this.logger.debug(`Open ...`)
if (this.virtualHostIsNotValid(params.virtualHost)) {
if (!this.virtualHostIsValid(params.virtualHost)) {
const errorMessage = `[ERROR]: VirtualHost '${params.virtualHost}' is not valid`
this.logger.error(errorMessage)
return { ok: false, error: new Error(errorMessage) }
Expand All @@ -487,8 +493,8 @@ export class Connection {
return { ok: true, response: res }
}

private virtualHostIsNotValid(virtualHost: string) {
if (!virtualHost) {
private virtualHostIsValid(virtualHost: string) {
if (isString(virtualHost) && virtualHost.length > 0) {
return true
}

Expand Down
2 changes: 2 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ export const ResponseCode = {
StreamDoesNotExist: 2,
SubscriptionIdDoesNotExist: 4,
} as const

export const isString = (value: unknown): boolean => typeof value === "string"
30 changes: 30 additions & 0 deletions test/unit/util.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { expect } from "chai"
import { isString } from "../../src/util"

describe("Util tests", () => {
describe("isString", () => {
it("return false with a number", () => {
const value = 1

expect(isString(value)).false
})

it("return false with a boolean", () => {
const value = false

expect(isString(value)).false
})

it("return true with a string", () => {
const value = "abc"

expect(isString(value)).true
})

it("return true with an empty string", () => {
const value = ""

expect(isString(value)).true
})
})
})