1 | /**
|
2 | * Kettle Single Request Tests common definitions
|
3 | *
|
4 | * Copyright 2016 Raising The Floor - International
|
5 | *
|
6 | * Licensed under the New BSD license. You may not use this file except in
|
7 | * compliance with this License.
|
8 | *
|
9 | * You may obtain a copy of the License at
|
10 | * https://github.com/fluid-project/kettle/blob/master/LICENSE.txt
|
11 | */
|
12 |
|
13 | ;
|
14 |
|
15 | var fluid = require("infusion"),
|
16 | kettle = fluid.require("%kettle");
|
17 |
|
18 | kettle.loadTestingSupport();
|
19 |
|
20 | // A template server config for all "single request" tests
|
21 | // TODO: this should never work if the server constructs asynchronously - need to merge with
|
22 | // kettle.test.serverEnvironment infrastructure
|
23 | fluid.defaults("kettle.tests.singleRequest.config", {
|
24 | gradeNames: "fluid.component",
|
25 | components: {
|
26 | server: {
|
27 | type: "kettle.server",
|
28 | options: {
|
29 | port: 8081,
|
30 | components: {
|
31 | app: {
|
32 | type: "kettle.app",
|
33 | options: {
|
34 | requestHandlers: {
|
35 | testHandler: {
|
36 | type: "kettle.request.http",
|
37 | route: "/",
|
38 | method: "get"
|
39 | }
|
40 | }
|
41 | }
|
42 | }
|
43 | }
|
44 | }
|
45 | }
|
46 | }
|
47 | });
|
48 |
|
49 | /** Merge the config testDefs, generate their grades derived from
|
50 | * "kettle.tests.singleRequest.config" and execute them **/
|
51 |
|
52 | /**
|
53 | * @param testDefs {Array of String} An array of the grade names holding
|
54 | * "hollow grades" to be merged into full fixtures
|
55 | * @param testDefTemplateGrade {String} The grade holding the
|
56 | * "test def template" including the actual test sequence and assertion
|
57 | * defaults to be merged into the hollow grades
|
58 | * @param errorExpect {Boolean} `true` If the `expect` count for the fixtures
|
59 | * is to be derived based on the `errorTexts` option.
|
60 | */
|
61 |
|
62 | kettle.tests.singleRequest.executeTests = function (testDefs, testDefTemplateGrade, errorExpect) {
|
63 | fluid.each(testDefs, function (testDefGrade) {
|
64 | var testDefDefaults = fluid.defaults(testDefGrade);
|
65 | var mergedConfigName = testDefGrade + ".mergedConfig";
|
66 | fluid.defaults(mergedConfigName, {
|
67 | gradeNames: "kettle.tests.singleRequest.config",
|
68 | distributeOptions: {
|
69 | target: "{that kettle.app}.options.requestHandlers.testHandler",
|
70 | record: testDefDefaults.handler
|
71 | }
|
72 | });
|
73 | var mergedTestDefName = testDefGrade + ".mergedTestDef";
|
74 | fluid.defaults(mergedTestDefName, {
|
75 | gradeNames: [testDefTemplateGrade, testDefGrade]
|
76 | });
|
77 | var fullTestDef = fluid.copy(fluid.defaults(mergedTestDefName));
|
78 | fullTestDef.configType = mergedConfigName;
|
79 | if (errorExpect) {
|
80 | fullTestDef.expect = 2 + fluid.makeArray(fullTestDef.errorTexts).length;
|
81 | } else {
|
82 | fullTestDef.expect = 2;
|
83 | }
|
84 | kettle.test.bootstrapServer(fullTestDef);
|
85 | });
|
86 | };
|