Skip to content

Commit e2925fc

Browse files
committed
Create tests for validateOptions
1 parent f5aba03 commit e2925fc

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

src/options/options.test.ts

+49-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { makeOptions } from "./options";
1+
import { makeOptions, validateOptions } from "./options";
22
import * as Mustache from "mustache";
33
import { Swagger } from "../swagger/Swagger";
44

@@ -37,3 +37,51 @@ describe("makeOptions", () => {
3737
expect(options.className).toBe("GeneratedDataLayer");
3838
});
3939
});
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

Comments
 (0)