-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk-node): Auth context for functions (#72)
* chore(sdk-node): Remove authenticate from registrations * chore(sdk-node): Customer auth context support
- Loading branch information
1 parent
7534f50
commit 3609beb
Showing
8 changed files
with
27 additions
and
88 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
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
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,54 +1,7 @@ | ||
import { executeFn } from "./execute-fn"; | ||
|
||
describe("executeFn", () => { | ||
it("should run a function with arguments", async () => { | ||
const fn = (val: { [key: string]: string }) => Promise.resolve(val.foo); | ||
const result = await fn({ foo: "bar" }); | ||
expect(result).toBe("bar"); | ||
}); | ||
|
||
it("should authenticate a function with valid context", async () => { | ||
const fn = (val: { [key: string]: string }) => Promise.resolve(val.foo); | ||
const args = { foo: "bar" }; | ||
const authenticate = ( | ||
authContext: string, | ||
args: { [key: string]: string }, | ||
) => { | ||
return args.foo === authContext | ||
? Promise.resolve() | ||
: Promise.reject(new Error("Unauthorized")); | ||
}; | ||
|
||
const result = executeFn(fn, [args], authenticate, "bar"); | ||
|
||
await expect(result).resolves.toEqual({ | ||
content: "bar", | ||
functionExecutionTime: expect.any(Number), | ||
type: "resolution", | ||
}); | ||
}); | ||
|
||
it("should authenticate a function with invalid context", async () => { | ||
const fn = (val: { [key: string]: string }) => Promise.resolve(val.foo); | ||
const args = { foo: "bar" }; | ||
const authenticate = ( | ||
authContext: string, | ||
args: { [key: string]: string }, | ||
) => { | ||
return args.foo === authContext | ||
? Promise.resolve() | ||
: Promise.reject(new Error("Unauthorized")); | ||
}; | ||
|
||
const result = executeFn(fn, [args], authenticate, "not-bar"); | ||
|
||
await expect(result).resolves.toEqual( | ||
expect.objectContaining({ | ||
type: "rejection", | ||
content: expect.objectContaining({ | ||
message: "Unauthorized", | ||
}), | ||
}), | ||
); | ||
}); | ||
}); |
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
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