All files / src/test-routes/dpg update.ts

0% Statements 0/31
0% Branches 0/7
0% Functions 0/9
0% Lines 0/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114                                                                                                                                                                                                                                   
import { app, json, ValidationError } from "../../api";
import { coverageService } from "../../services";
 
/**
 * Scenarios to test DPG and RLC Service driven evolution.
 * These scenarios here are considered acceptable from an Azure breaking change policy
 */
app.category("dpg", () => {
  /**
   * Initially has no query parameters. After evolution, a new optional query parameter is added.
   * Note that when defining HEAD and GET methods for the same path, HEAD needs to be defined before
   * GET. Otherwise Express would register the GET handler as the handler for both and the app.head would be ignored.
   */
  app.head("/servicedriven/parameters", "DPGAddOptionalInput_NoParams", (req) => {
    return {
      status: 200,
      headers: { "content-length": "123" },
    };
  });
 
  /**
   * Initially only has one required Query Parameter. After evolution, a new optional query parameter is added.
   */
  app.get("/servicedriven/parameters", "DPGAddOptionalInput", (req) => {
    if (req.query["parameter"]) {
      return {
        status: 200,
        body: json({ message: `An object was successfully returned` }),
      };
    } else {
      return {
        status: 400,
        body: json({ message: `Expected required parameter "parameter"` }),
      };
    }
  });
 
  /**
   * Initially has one required query parameter and one optional query parameter.  After evolution, a new optional query parameter is added
   */
  app.put("/servicedriven/parameters", "DPGAddOptionalInput_RequiredOptionalParam", (req) => {
    if (req.query["requiredParam"]) {
      return {
        status: 200,
        body: json({ message: `An object was successfully returned` }),
      };
    } else {
      return {
        status: 400,
        body: json({ message: `Expected required parameter "requiredParam"` }),
      };
    }
  });
 
  /**
   * Initially has one optional query parameter. After evolution, a new optional query parameter is added
   */
  app.get("/serviceDriven/moreParameters", "DPGAddOptionalInput_OptionalParam", (req) => {
    return {
      status: 200,
      body: json({ message: `An object was successfully returned` }),
    };
  });
 
  /**
   * A new body type is added (was JSON, and now JSON + JPEG).
   */
  coverageService.register("dpg", "DPGNewBodyType.JSON");
  coverageService.register("dpg", "DPGNewBodyType.JPEG");
  app.post("/servicedriven/parameters", "DPGNewBodyType", (req) => {
    switch (req.headers["content-type"]) {
      case "image/jpeg":
        // req.expect.rawBodyEquals("binary");
        coverageService.track("dpg", "DPGNewBodyType.JPEG");
        return { status: 200 };
      case "application/json":
        req.expect.bodyEquals({ url: "http://example.org/myimage.jpeg" });
        coverageService.track("dpg", "DPGNewBodyType.JSON");
        return { status: 200 };
      default:
        throw new ValidationError("Should be image/jpeg or application/json", {}, req.headers["content-type"]);
    }
  });
 
  /**
   * Initially the path exists but there is no delete method. After evolution this is a new method in a known path
   */
  app.delete("/servicedriven/parameters", "DPGAddNewOperation", (req) => {
    return {
      status: 204,
    };
  });
 
  /**
   * Initially neither path or method exist for this operation. After evolution, this is a new method in a new path
   */
  app.get("/servicedriven/newpath", "DPGAddNewPath", (req) => {
    return {
      status: 200,
      body: json({ message: `An object was successfully returned` }),
    };
  });
 
  /**
   * An operation that is not part of the swagger definition but can be called
   */
  app.get("/servicedriven/glassbreaker", "DPGGlassBreaker", (req) => {
    return {
      status: 200,
      body: json({ message: `An object was successfully returned` }),
    };
  });
});