-
Notifications
You must be signed in to change notification settings - Fork 592
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add and apply accountIdDefaultMiddleware
- Loading branch information
Chase Coalwell
committed
Dec 10, 2019
1 parent
724370e
commit 691abb3
Showing
6 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/middleware-sdk-glacier/src/account-id-default.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { accountIdDefaultMiddleware } from "./account-id-default"; | ||
|
||
describe("accountIdDefaultMiddleware", () => { | ||
const next = jest.fn(); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("adds default accountId if not set on input", async () => { | ||
const handler = accountIdDefaultMiddleware()(next, {} as any); | ||
await handler({ | ||
input: {} | ||
}); | ||
|
||
expect(next.mock.calls.length).toBe(1); | ||
expect(next).toHaveBeenCalledWith({ | ||
input: { | ||
accountId: "-" | ||
} | ||
}); | ||
}); | ||
|
||
it("does not change accountId input if set previously", async () => { | ||
const handler = accountIdDefaultMiddleware()(next, {} as any); | ||
await handler({ | ||
input: { | ||
accountId: "1234" | ||
} | ||
}); | ||
|
||
expect(next.mock.calls.length).toBe(1); | ||
expect(next).toHaveBeenCalledWith({ | ||
input: { | ||
accountId: "1234" | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { | ||
InitializeHandler, | ||
InitializeHandlerArguments, | ||
InitializeHandlerOptions, | ||
InitializeHandlerOutput, | ||
InitializeMiddleware, | ||
MetadataBearer, | ||
Pluggable | ||
} from "@aws-sdk/types"; | ||
|
||
export function accountIdDefaultMiddleware(): InitializeMiddleware<any, any> { | ||
return <Output extends MetadataBearer>( | ||
next: InitializeHandler<any, Output> | ||
): InitializeHandler<any, Output> => async ( | ||
args: InitializeHandlerArguments<any> | ||
): Promise<InitializeHandlerOutput<Output>> => { | ||
const { input } = args; | ||
if (input.accountId === undefined) { | ||
input.accountId = "-"; | ||
} | ||
return next({ ...args, input }); | ||
}; | ||
} | ||
|
||
export const accountIdDefaultMiddlewareOptions: InitializeHandlerOptions = { | ||
step: "initialize", | ||
tags: ["ACCOUNT_ID_DEFAULT"], | ||
name: "accountIdDefaultMiddleware" | ||
}; | ||
|
||
export const getAccountIdDefaultPlugin = ( | ||
unused: any | ||
): Pluggable<any, any> => ({ | ||
applyToStack: clientStack => { | ||
clientStack.add( | ||
accountIdDefaultMiddleware(), | ||
accountIdDefaultMiddlewareOptions | ||
); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
import { addGlacierApiVersionMiddleware } from "./index"; | ||
import { | ||
accountIdDefaultMiddleware, | ||
addGlacierApiVersionMiddleware | ||
} from "./index"; | ||
|
||
describe("middleware-sdk-glacier package exports", () => { | ||
it("addGlacierApiVersionMiddleware", () => { | ||
expect(typeof addGlacierApiVersionMiddleware).toBe("function"); | ||
}); | ||
|
||
it("accountIdDefaultMiddleware", () => { | ||
expect(typeof accountIdDefaultMiddleware).toBe("function"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./add-glacier-api-version"; | ||
export * from "./account-id-default"; |