|
1 |
| -import { makeOptions } from "./options"; |
| 1 | +import { makeOptions, validateOptions } from "./options"; |
2 | 2 | import * as Mustache from "mustache";
|
3 | 3 | import { Swagger } from "../swagger/Swagger";
|
4 | 4 |
|
@@ -37,3 +37,51 @@ describe("makeOptions", () => {
|
37 | 37 | expect(options.className).toBe("GeneratedDataLayer");
|
38 | 38 | });
|
39 | 39 | });
|
| 40 | + |
| 41 | +describe("validateOptions", () => { |
| 42 | + it("with valid options", () => { |
| 43 | + const partialOptions = { |
| 44 | + swagger: {} as Swagger, |
| 45 | + template: { |
| 46 | + class: "class-template", |
| 47 | + method: "method-template" |
| 48 | + } |
| 49 | + }; |
| 50 | + |
| 51 | + const options = makeOptions(partialOptions); |
| 52 | + |
| 53 | + expect(() => validateOptions(options)); |
| 54 | + }); |
| 55 | + |
| 56 | + it("throws when class template is not provided", () => { |
| 57 | + const partialOptions = { |
| 58 | + swagger: {} as Swagger, |
| 59 | + template: { |
| 60 | + class: "class-template", |
| 61 | + method: undefined |
| 62 | + } |
| 63 | + }; |
| 64 | + |
| 65 | + const options = makeOptions(partialOptions); |
| 66 | + |
| 67 | + expect(() => validateOptions(options)).toThrow( |
| 68 | + 'Unprovided custom template. Please use the following template: template: { class: "...", method: "...", request: "..." }' |
| 69 | + ); |
| 70 | + }); |
| 71 | + |
| 72 | + it("throws when method template is not provided", () => { |
| 73 | + const partialOptions = { |
| 74 | + swagger: {} as Swagger, |
| 75 | + template: { |
| 76 | + class: undefined, |
| 77 | + method: "method-template" |
| 78 | + } |
| 79 | + }; |
| 80 | + |
| 81 | + const options = makeOptions(partialOptions); |
| 82 | + |
| 83 | + expect(() => validateOptions(options)).toThrow( |
| 84 | + 'Unprovided custom template. Please use the following template: template: { class: "...", method: "...", request: "..." }' |
| 85 | + ); |
| 86 | + }); |
| 87 | +}); |
0 commit comments