Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Format code with Prettier #16

Closed
wants to merge 3 commits into from
Closed
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
38 changes: 20 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
name: http-tests
on:
on:
push:
branches:
- master
paths-ignore:
- '**.md'
- "**.md"
pull_request:
paths-ignore:
- '**.md'
- "**.md"

jobs:

build:
name: Build

Expand All @@ -23,22 +22,25 @@ jobs:
runs-on: ${{ matrix.runs-on }}

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v2

- name: Setup node
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Setup node
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install
run: npm install

- name: npm install
run: npm install
- name: Compile
run: npm run build

- name: Compile
run: npm run build
- name: Format
run: npm run format-check

- name: npm test
run: npm test
- name: npm test
run: npm test

- name: audit security
run: npm audit
- name: audit security
run: npm audit
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_out/*
117 changes: 67 additions & 50 deletions __tests__/auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,73 @@
import * as httpm from '../_out';
import * as am from '../_out/auth';
import * as httpm from "../_out";
import * as am from "../_out/auth";

describe('auth', () => {
beforeEach(() => {
describe("auth", () => {
beforeEach(() => {});

})

afterEach(() => {
afterEach(() => {});

})

it('does basic http get request with basic auth', async() => {
let bh: am.BasicCredentialHandler = new am.BasicCredentialHandler('johndoe', 'password');
let http: httpm.HttpClient = new httpm.HttpClient('http-client-tests', [bh]);
let res: httpm.HttpClientResponse = await http.get('http://httpbin.org/get');
expect(res.message.statusCode).toBe(200);
let body: string = await res.readBody();
let obj:any = JSON.parse(body);
let auth: string = obj.headers.Authorization;
let creds: string = Buffer.from(auth.substring('Basic '.length), 'base64').toString();
expect(creds).toBe('johndoe:password');
expect(obj.url).toBe("http://httpbin.org/get");
});
it("does basic http get request with basic auth", async () => {
let bh: am.BasicCredentialHandler = new am.BasicCredentialHandler(
"johndoe",
"password"
);
let http: httpm.HttpClient = new httpm.HttpClient("http-client-tests", [
bh,
]);
let res: httpm.HttpClientResponse = await http.get(
"http://httpbin.org/get"
);
expect(res.message.statusCode).toBe(200);
let body: string = await res.readBody();
let obj: any = JSON.parse(body);
let auth: string = obj.headers.Authorization;
let creds: string = Buffer.from(
auth.substring("Basic ".length),
"base64"
).toString();
expect(creds).toBe("johndoe:password");
expect(obj.url).toBe("http://httpbin.org/get");
});

it('does basic http get request with pat token auth', async() => {
let token: string = 'scbfb44vxzku5l4xgc3qfazn3lpk4awflfryc76esaiq7aypcbhs';
let ph: am.PersonalAccessTokenCredentialHandler =
new am.PersonalAccessTokenCredentialHandler(token);
it("does basic http get request with pat token auth", async () => {
let token: string = "scbfb44vxzku5l4xgc3qfazn3lpk4awflfryc76esaiq7aypcbhs";
let ph: am.PersonalAccessTokenCredentialHandler = new am.PersonalAccessTokenCredentialHandler(
token
);

let http: httpm.HttpClient = new httpm.HttpClient('http-client-tests', [ph]);
let res: httpm.HttpClientResponse = await http.get('http://httpbin.org/get');
expect(res.message.statusCode).toBe(200);
let body: string = await res.readBody();
let obj:any = JSON.parse(body);
let auth: string = obj.headers.Authorization;
let creds: string = Buffer.from(auth.substring('Basic '.length), 'base64').toString();
expect(creds).toBe('PAT:' + token);
expect(obj.url).toBe("http://httpbin.org/get");
});

it('does basic http get request with pat token auth', async() => {
let token: string = 'scbfb44vxzku5l4xgc3qfazn3lpk4awflfryc76esaiq7aypcbhs';
let ph: am.BearerCredentialHandler =
new am.BearerCredentialHandler(token);
let http: httpm.HttpClient = new httpm.HttpClient("http-client-tests", [
ph,
]);
let res: httpm.HttpClientResponse = await http.get(
"http://httpbin.org/get"
);
expect(res.message.statusCode).toBe(200);
let body: string = await res.readBody();
let obj: any = JSON.parse(body);
let auth: string = obj.headers.Authorization;
let creds: string = Buffer.from(
auth.substring("Basic ".length),
"base64"
).toString();
expect(creds).toBe("PAT:" + token);
expect(obj.url).toBe("http://httpbin.org/get");
});

let http: httpm.HttpClient = new httpm.HttpClient('http-client-tests', [ph]);
let res: httpm.HttpClientResponse = await http.get('http://httpbin.org/get');
expect(res.message.statusCode).toBe(200);
let body: string = await res.readBody();
let obj:any = JSON.parse(body);
let auth: string = obj.headers.Authorization;
expect(auth).toBe('Bearer ' + token);
expect(obj.url).toBe("http://httpbin.org/get");
});
})
it("does basic http get request with pat token auth", async () => {
let token: string = "scbfb44vxzku5l4xgc3qfazn3lpk4awflfryc76esaiq7aypcbhs";
let ph: am.BearerCredentialHandler = new am.BearerCredentialHandler(token);

let http: httpm.HttpClient = new httpm.HttpClient("http-client-tests", [
ph,
]);
let res: httpm.HttpClientResponse = await http.get(
"http://httpbin.org/get"
);
expect(res.message.statusCode).toBe(200);
let body: string = await res.readBody();
let obj: any = JSON.parse(body);
let auth: string = obj.headers.Authorization;
expect(auth).toBe("Bearer " + token);
expect(obj.url).toBe("http://httpbin.org/get");
});
});
Loading