Skip to content

Commit

Permalink
specs, fix mockapi in auth scenarios (#752)
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft authored Oct 16, 2024
1 parent afce8be commit 46e3022
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .changeset/polite-jeans-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@azure-tools/cadl-ranch-api": minor
"@azure-tools/cadl-ranch-specs": patch
---

Fix mockapi in authentication scenarios.
3 changes: 1 addition & 2 deletions packages/cadl-ranch-api/src/scenarios.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
KeyedMockApi,
KeyedMockApiDefinition,
KeyedMockRequestHandler,
MockApi,
MockApiDefinition,
PassByKeyScenario,
Expand All @@ -27,7 +26,7 @@ export function passOnSuccess(
* @param code Status code all endpoint should return
* @param apis Endpoint or List of endpoints for this scenario
*/
export function passOnCode(code: number, apis: MockApi | readonly MockApi[]): PassOnCodeScenario {
export function passOnCode(code: number, apis: MockApi | readonly MockApi[] | MockApiDefinition): PassOnCodeScenario {
return {
passCondition: "status-code",
code,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { json, MockRequest, passOnSuccess } from "@azure-tools/cadl-ranch-api";
import { json, MockRequest, passOnCode, passOnSuccess } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};
Expand All @@ -21,12 +21,12 @@ Scenarios.Authentication_ApiKey_valid = passOnSuccess({
kind: "MockApiDefinition",
});

Scenarios.Authentication_ApiKey_invalid = passOnSuccess({
Scenarios.Authentication_ApiKey_invalid = passOnCode(403, {
uri: `/authentication/api-key/invalid`,
method: `get`,
request: {
headers: {
"x-ms-api-key": "valid-key",
"x-ms-api-key": "invalid-key",
},
status: 403,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { json, MockRequest, passOnSuccess } from "@azure-tools/cadl-ranch-api";
import { json, MockRequest, passOnSuccess, passOnCode } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};
Expand All @@ -21,12 +21,12 @@ Scenarios.Authentication_Http_Custom_valid = passOnSuccess({
kind: "MockApiDefinition",
});

Scenarios.Authentication_Http_Custom_invalid = passOnSuccess({
Scenarios.Authentication_Http_Custom_invalid = passOnCode(403, {
uri: `/authentication/http/custom/invalid`,
method: "get",
request: {
headers: {
authorization: "SharedAccessKey valid-key",
authorization: "SharedAccessKey invalid-key",
},
status: 403,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { json, MockRequest, passOnSuccess } from "@azure-tools/cadl-ranch-api";
import { json, MockRequest, passOnSuccess, passOnCode } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};
Expand All @@ -21,7 +21,7 @@ Scenarios.Authentication_OAuth2_valid = passOnSuccess({
kind: "MockApiDefinition",
});

Scenarios.Authentication_OAuth2_invalid = passOnSuccess({
Scenarios.Authentication_OAuth2_invalid = passOnCode(403, {
uri: `/authentication/oauth2/invalid`,
method: "get",
request: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { passOnSuccess, json, MockApiDefinition, MockRequest } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";
import { Mock } from "node:test";

export const Scenarios: Record<string, ScenarioMockApi> = {};
function createMockApiDefinitions(route: string, request: any, response: any): MockApiDefinition {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";
import { Mock } from "node:test";

export const Scenarios: Record<string, ScenarioMockApi> = {};

Expand Down

0 comments on commit 46e3022

Please sign in to comment.