Skip to content

Commit

Permalink
fix tests and remove localstack
Browse files Browse the repository at this point in the history
  • Loading branch information
zirkelc committed Jan 15, 2024
1 parent cc028e6 commit a4adfa4
Show file tree
Hide file tree
Showing 11 changed files with 315 additions and 242 deletions.
13 changes: 1 addition & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_REGION: ${{ secrets.AWS_REGION }}

jobs:
lint:
Expand All @@ -30,7 +29,7 @@ jobs:
- name: Lint
run: |
npm run lint:ci
npm run lint
tests:
name: Tests
Expand All @@ -50,16 +49,6 @@ jobs:
cache: 'npm'
cache-dependency-path: '**/package-lock.json'

- name: Start LocalStack
run: |
pip install localstack awscli-local[ver1] # install LocalStack cli and awslocal
docker pull localstack/localstack # Make sure to pull the latest version of the image
localstack start -d # Start LocalStack in the background
echo "Waiting for LocalStack startup..." # Wait 30 seconds for the LocalStack container
localstack wait -t 30 # to become ready before timing out
echo "Startup complete"
- name: Install
id: install
run: |
Expand Down
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"configurations": [
{
"type": "node-terminal",
"name": "Debug Test File (npm run test)",
"name": "Run Test (pnpm test)",
"request": "launch",
"command": "npm run test -- ${relativeFile}",
"command": "pnpm test -- ${relativeFile}",
"cwd": "${fileDirname}"
},
]
Expand Down
9 changes: 5 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"quickfix.rome": true
"quickfix.biome": "explicit",
"source.organizeImports.biome": true
},
"[javascript]": {
"editor.defaultFormatter": "rome.rome",
"editor.defaultFormatter": "biomejs.biome",
},
"[typescript]": {
"editor.defaultFormatter": "rome.rome",
"editor.defaultFormatter": "biomejs.biome",
}
}
}
142 changes: 102 additions & 40 deletions __tests__/iam.test.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,102 @@
import { describe, it, expect } from 'vitest';
import 'cross-fetch/polyfill';
import { createSignedFetcher } from '../dist/index';

describe('IAM', () => {
describe('GET', () => {
it('should get current user', async () => {
const url = 'https://iam.amazonaws.com/?Action=GetUser&Version=2010-05-08';

const fetch = createSignedFetcher({ service: 'iam', region: 'us-east-1' });
const response = await fetch(url, {
method: 'GET'
});

expect(response.status).toBe(200);

const data = await response.text();
expect(data).toContain('<GetUserResult>');
})
})

describe('POST', () => {
it('should get current user', async () => {
const url = 'https://iam.amazonaws.com/';
const body = 'Action=GetUser&Version=2010-05-08'

const fetch = createSignedFetcher({ service: 'iam', region: 'us-east-1' });
const response = await fetch(url, {
method: 'POST',
body,
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8' }
});

expect(response.status).toBe(200);

const data = await response.text();
expect(data).toContain('<GetUserResult>');
})
})
})
import "cross-fetch/polyfill";
import { describe, expect, it } from "vitest";
import { createSignedFetcher } from "../dist/index";

describe("IAM", () => {
it("should handle GET", async () => {
const url = "https://iam.amazonaws.com/?Action=GetUser&Version=2010-05-08";

const fetch = createSignedFetcher({ service: "iam", region: "us-east-1" });
const response = await fetch(url, {
method: "GET",
});

expect(response.status).toBe(200);

const data = await response.text();
expect(data).toContain("<GetUserResult>");
});

it("should handle POST", async () => {
const url = "https://iam.amazonaws.com/";
const body = "Action=GetUser&Version=2010-05-08";

const fetch = createSignedFetcher({ service: "iam", region: "us-east-1" });
const response = await fetch(url, {
method: "POST",
body,
headers: {
"Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
},
});

expect(response.status).toBe(200);

const data = await response.text();
expect(data).toContain("<GetUserResult>");
});

it("should handle additional headers", async () => {
const url = "https://iam.amazonaws.com/?Action=GetUser&Version=2010-05-08";

const headers = {
"x-amz-test-header": "test-value",
"x-api-key": "test-api-key",
};

const fetch = createSignedFetcher({
service: "iam",
region: "us-east-1",
});

const response = await fetch(url, {
method: "GET",
headers,
});

expect(response.status).toBe(200);

const data = await response.text();
expect(data).toContain("<GetUserResult>");
});

it("should handle url fragments", async () => {
const url =
"https://iam.amazonaws.com/?Action=GetUser&Version=2010-05-08#test-fragment";

const fetch = createSignedFetcher({
service: "iam",
region: "us-east-1",
});

const response = await fetch(url, {
method: "GET",
});

expect(response.status).toBe(200);

const data = await response.text();
expect(data).toContain("<GetUserResult>");
});

it("should abort request", async () => {
const url = "https://iam.amazonaws.com/?Action=GetUser&Version=2010-05-08";

const controller = new AbortController();
const signal = controller.signal;

const fetch = createSignedFetcher({
service: "iam",
region: "us-east-1",
});

const response = fetch(url, {
method: "GET",
signal,
});

controller.abort();

await expect(response).rejects.toThrow("This operation was aborted");
});
});
18 changes: 18 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.1/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"suspicious": {
"noExplicitAny": "off"
},
"complexity": {
"useLiteralKeys": "off"
}
}
}
}
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
"README.md"
],
"scripts": {
"start": "localstack start",
"test": "vitest",
"pretest": "pnpm build && pnpm start",
"build": "rm -rf dist && tsc",
"prepublishOnly": "pnpm build",
"lint": "pnpm rome check ./src",
"lint:ci": "pnpm rome ci ./src",
"format": "pnpm rome format ./src --write"
"lint": "pnpm biome lint ./src",
"format": "pnpm biome format ./src --write"
},
"repository": {
"type": "git",
Expand All @@ -40,9 +38,9 @@
"@aws-sdk/types": "^3.357.0"
},
"devDependencies": {
"@biomejs/biome": "1.5.1",
"@tsconfig/node16": "^16.1.0",
"cross-fetch": "^4.0.0",
"rome": "12.1.3",
"typescript": "^5.2.0",
"vitest": "^0.34.6"
}
Expand Down
Loading

0 comments on commit a4adfa4

Please sign in to comment.