-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: implement substitute builder for secrets manager
- Loading branch information
1 parent
80245a5
commit 70a5f87
Showing
3 changed files
with
114 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./substituteBuilder"; |
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,50 @@ | ||
import { | ||
GetSecretValueCommandOutput, | ||
SecretsManagerClient, | ||
} from "@aws-sdk/client-secrets-manager"; | ||
import Substitute, { Arg, SubstituteOf } from "@fluffy-spoon/substitute"; | ||
|
||
export class SubstituteBuilder { | ||
static forSecretsManager(): SecretsManagerSubstituteBuilder { | ||
return new SecretsManagerSubstituteBuilder(); | ||
} | ||
} | ||
|
||
class SecretsManagerSubstituteBuilder { | ||
public substitute: SubstituteOf<SecretsManagerClient>; | ||
|
||
constructor() { | ||
this.substitute = Substitute.for<SecretsManagerClient>(); | ||
} | ||
|
||
mockGetSecretValue() { | ||
return new GetSecretValueSubstituteBuilder(this.substitute); | ||
} | ||
} | ||
|
||
class GetSecretValueSubstituteBuilder { | ||
private secretString?: string; | ||
|
||
constructor( | ||
private readonly substitute: SubstituteOf<SecretsManagerClient>, | ||
) {} | ||
|
||
withSecretString(secretString: string) { | ||
this.secretString = secretString; | ||
return this; | ||
} | ||
|
||
failsWith(error: Error) { | ||
this.substitute.send(Arg.all()).rejects(error); | ||
return this.substitute; | ||
} | ||
|
||
succeeds() { | ||
const substituteResponse = Substitute.for<GetSecretValueCommandOutput>(); | ||
substituteResponse.SecretString?.returns?.(this.secretString); | ||
|
||
this.substitute.send(Arg.all()).resolves(substituteResponse); | ||
|
||
return this.substitute; | ||
} | ||
} |