Skip to content

Commit

Permalink
Handle port being either a string or number at runtime. Use string pr…
Browse files Browse the repository at this point in the history
…imative not String object wrapper which works with parseInt
  • Loading branch information
halkeye authored and niekcandaele committed Apr 23, 2020
1 parent 04b2706 commit 54cb4ff
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 67 deletions.
12 changes: 6 additions & 6 deletions lib/index.ts
Expand Up @@ -2,20 +2,20 @@ import fetch, { RequestInit } from "node-fetch"
import * as responses from './responses'

export interface SdtdServer {
ip: String,
port: String,
ip: string,
port: string,
forceHttps?: Boolean,
adminUser: String,
adminToken: String
adminUser: string,
adminToken: string
}

export function getBaseUrl(server: SdtdServer): String {
export function getBaseUrl(server: SdtdServer): string {
let scheme = "http";
if (server.forceHttps === true) {
scheme = "https"
} else if (server.forceHttps === false) {
scheme = "http"
} else if (server.port === "443") {
} else if (parseInt(server.port) === 443) {
scheme = "https"
}
return `${scheme}://${server.ip}:${server.port}`;
Expand Down
8 changes: 4 additions & 4 deletions test/executeConsoleCommand.test.ts
Expand Up @@ -9,10 +9,10 @@ require('dotenv').config()
chai.use(chaiAsPromised)

let testServer: SdtdServer = {
ip: process.env.TESTIP as String,
port: process.env.TESTPORT as String,
adminUser: process.env.TESTADMINUSER as String,
adminToken: process.env.TESTADMINTOKEN as String
ip: process.env.TESTIP as string,
port: process.env.TESTPORT as string,
adminUser: process.env.TESTADMINUSER as string,
adminToken: process.env.TESTADMINTOKEN as string
}

describe('/api/executeconsolecommand', async () => {
Expand Down
10 changes: 5 additions & 5 deletions test/getAllowedCommands.test.ts
Expand Up @@ -2,17 +2,17 @@
import * as chai from 'chai'
import * as chaiAsPromised from 'chai-as-promised'
import { SdtdServer } from '../lib/index'
let SdtdApi = require('../lib/index.js');
let SdtdApi = require('../lib/index');

require('dotenv').config()

chai.use(chaiAsPromised)

let testServer: SdtdServer = {
ip: process.env.TESTIP as String,
port: process.env.TESTPORT as String,
adminUser: process.env.TESTADMINUSER as String,
adminToken: process.env.TESTADMINTOKEN as String
ip: process.env.TESTIP as string,
port: process.env.TESTPORT as string,
adminUser: process.env.TESTADMINUSER as string,
adminToken: process.env.TESTADMINTOKEN as string
}

describe('/api/getAllowedCommands', async () => {
Expand Down
8 changes: 4 additions & 4 deletions test/getAnimalsLocation.test.ts
Expand Up @@ -9,10 +9,10 @@ require('dotenv').config()
chai.use(chaiAsPromised)

let testServer: SdtdServer = {
ip: process.env.TESTIP as String,
port: process.env.TESTPORT as String,
adminUser: process.env.TESTADMINUSER as String,
adminToken: process.env.TESTADMINTOKEN as String
ip: process.env.TESTIP as string,
port: process.env.TESTPORT as string,
adminUser: process.env.TESTADMINUSER as string,
adminToken: process.env.TESTADMINTOKEN as string
}

describe('/api/getAnimalsLocation', async () => {
Expand Down
8 changes: 4 additions & 4 deletions test/getBaseUrl.test.ts
Expand Up @@ -6,10 +6,10 @@ import { getBaseUrl, SdtdServer } from '../lib/index'
chai.use(chaiAsPromised)

let testServer: SdtdServer = {
ip: process.env.TESTIP as String,
port: process.env.TESTPORT as String,
adminUser: process.env.TESTADMINUSER as String,
adminToken: process.env.TESTADMINTOKEN as String
ip: process.env.TESTIP as string,
port: process.env.TESTPORT as string,
adminUser: process.env.TESTADMINUSER as string,
adminToken: process.env.TESTADMINTOKEN as string
}

describe('getBaseUrl', async () => {
Expand Down
8 changes: 4 additions & 4 deletions test/getHostileLocation.test.ts
Expand Up @@ -9,10 +9,10 @@ require('dotenv').config()
chai.use(chaiAsPromised)

let testServer: SdtdServer = {
ip: process.env.TESTIP as String,
port: process.env.TESTPORT as String,
adminUser: process.env.TESTADMINUSER as String,
adminToken: process.env.TESTADMINTOKEN as String
ip: process.env.TESTIP as string,
port: process.env.TESTPORT as string,
adminUser: process.env.TESTADMINUSER as string,
adminToken: process.env.TESTADMINTOKEN as string
}

describe('/api/getHostileLocation', async () => {
Expand Down
8 changes: 4 additions & 4 deletions test/getLandClaims.test.ts
Expand Up @@ -9,10 +9,10 @@ require('dotenv').config()
chai.use(chaiAsPromised)

let testServer: SdtdServer = {
ip: process.env.TESTIP as String,
port: process.env.TESTPORT as String,
adminUser: process.env.TESTADMINUSER as String,
adminToken: process.env.TESTADMINTOKEN as String
ip: process.env.TESTIP as string,
port: process.env.TESTPORT as string,
adminUser: process.env.TESTADMINUSER as string,
adminToken: process.env.TESTADMINTOKEN as string
}

describe('/api/getLandClaims', async () => {
Expand Down
8 changes: 4 additions & 4 deletions test/getLog.test.ts
Expand Up @@ -9,10 +9,10 @@ require('dotenv').config()
chai.use(chaiAsPromised)

const testServer: SdtdServer = {
ip: process.env.TESTIP as String,
port: process.env.TESTPORT as String,
adminUser: process.env.TESTADMINUSER as String,
adminToken: process.env.TESTADMINTOKEN as String
ip: process.env.TESTIP as string,
port: process.env.TESTPORT as string,
adminUser: process.env.TESTADMINUSER as string,
adminToken: process.env.TESTADMINTOKEN as string
}

describe('/api/getLog', async () => {
Expand Down
8 changes: 4 additions & 4 deletions test/getOnlinePlayers.test.ts
Expand Up @@ -9,10 +9,10 @@ require('dotenv').config()
chai.use(chaiAsPromised)

let testServer: SdtdServer = {
ip: process.env.TESTIP as String,
port: process.env.TESTPORT as String,
adminUser: process.env.TESTADMINUSER as String,
adminToken: process.env.TESTADMINTOKEN as String
ip: process.env.TESTIP as string,
port: process.env.TESTPORT as string,
adminUser: process.env.TESTADMINUSER as string,
adminToken: process.env.TESTADMINTOKEN as string
}

describe('/api/getOnlinePlayers', async () => {
Expand Down
8 changes: 4 additions & 4 deletions test/getPlayerInventories.test.ts
Expand Up @@ -9,10 +9,10 @@ require('dotenv').config()
chai.use(chaiAsPromised)

let testServer: SdtdServer = {
ip: process.env.TESTIP as String,
port: process.env.TESTPORT as String,
adminUser: process.env.TESTADMINUSER as String,
adminToken: process.env.TESTADMINTOKEN as String
ip: process.env.TESTIP as string,
port: process.env.TESTPORT as string,
adminUser: process.env.TESTADMINUSER as string,
adminToken: process.env.TESTADMINTOKEN as string
}

describe('/api/getPlayerInventories', async () => {
Expand Down
8 changes: 4 additions & 4 deletions test/getPlayerInventory.test.ts
Expand Up @@ -9,10 +9,10 @@ require('dotenv').config()
chai.use(chaiAsPromised)

let testServer: SdtdServer = {
ip: process.env.TESTIP as String,
port: process.env.TESTPORT as String,
adminUser: process.env.TESTADMINUSER as String,
adminToken: process.env.TESTADMINTOKEN as String
ip: process.env.TESTIP as string,
port: process.env.TESTPORT as string,
adminUser: process.env.TESTADMINUSER as string,
adminToken: process.env.TESTADMINTOKEN as string
}
describe('/api/getPlayerInventory', async () => {
it('Returns a playername, bag, belt and equipment', async () => {
Expand Down
8 changes: 4 additions & 4 deletions test/getPlayerList.test.ts
Expand Up @@ -9,10 +9,10 @@ require('dotenv').config()
chai.use(chaiAsPromised)

let testServer: SdtdServer = {
ip: process.env.TESTIP as String,
port: process.env.TESTPORT as String,
adminUser: process.env.TESTADMINUSER as String,
adminToken: process.env.TESTADMINTOKEN as String
ip: process.env.TESTIP as string,
port: process.env.TESTPORT as string,
adminUser: process.env.TESTADMINUSER as string,
adminToken: process.env.TESTADMINTOKEN as string
}
describe('/api/getPlayerList', async () => {
it('Returns expected output', async () => {
Expand Down
8 changes: 4 additions & 4 deletions test/getPlayersLocation.test.ts
Expand Up @@ -9,10 +9,10 @@ require('dotenv').config()
chai.use(chaiAsPromised)

let testServer: SdtdApi.SdtdServer = {
ip: process.env.TESTIP as String,
port: process.env.TESTPORT as String,
adminUser: process.env.TESTADMINUSER as String,
adminToken: process.env.TESTADMINTOKEN as String
ip: process.env.TESTIP as string,
port: process.env.TESTPORT as string,
adminUser: process.env.TESTADMINUSER as string,
adminToken: process.env.TESTADMINTOKEN as string
}

describe('/api/getPlayersLocation', async () => {
Expand Down
8 changes: 4 additions & 4 deletions test/getServerInfo.test.ts
Expand Up @@ -9,10 +9,10 @@ require('dotenv').config()
chai.use(chaiAsPromised)

let testServer: SdtdServer = {
ip: process.env.TESTIP as String,
port: process.env.TESTPORT as String,
adminUser: process.env.TESTADMINUSER as String,
adminToken: process.env.TESTADMINTOKEN as String
ip: process.env.TESTIP as string,
port: process.env.TESTPORT as string,
adminUser: process.env.TESTADMINUSER as string,
adminToken: process.env.TESTADMINTOKEN as string
}
describe('/api/getServerInfo', async () => {
it('Returns expected output', async () => {
Expand Down
8 changes: 4 additions & 4 deletions test/getStats.test.ts
Expand Up @@ -9,10 +9,10 @@ require('dotenv').config()
chai.use(chaiAsPromised)

let testServer: SdtdServer = {
ip: process.env.TESTIP as String,
port: process.env.TESTPORT as String,
adminUser: process.env.TESTADMINUSER as String,
adminToken: process.env.TESTADMINTOKEN as String
ip: process.env.TESTIP as string,
port: process.env.TESTPORT as string,
adminUser: process.env.TESTADMINUSER as string,
adminToken: process.env.TESTADMINTOKEN as string
}

describe('/api/getstats', async () => {
Expand Down
8 changes: 4 additions & 4 deletions test/getWebUIUpdates.test.ts
Expand Up @@ -9,10 +9,10 @@ require('dotenv').config()
chai.use(chaiAsPromised)

let testServer: SdtdServer = {
ip: process.env.TESTIP as String,
port: process.env.TESTPORT as String,
adminUser: process.env.TESTADMINUSER as String,
adminToken: process.env.TESTADMINTOKEN as String
ip: process.env.TESTIP as string,
port: process.env.TESTPORT as string,
adminUser: process.env.TESTADMINUSER as string,
adminToken: process.env.TESTADMINTOKEN as string
}

describe('/api/getWebUIUpdates', async () => {
Expand Down

0 comments on commit 54cb4ff

Please sign in to comment.