Adding tests for validating readOnly properties

This commit is contained in:
Amar Zavery 2019-05-29 12:33:31 -07:00
Родитель 3b1febbb9f
Коммит dd0cd8cf5c
5 изменённых файлов: 1281 добавлений и 3 удалений

Просмотреть файл

@ -36,7 +36,7 @@
"vscode-jsonrpc": "^3.6.2",
"winston": "^3.2.1",
"yargs": "^6.6.0",
"yasway": "^1.7.1",
"yasway": "Azure/sway#readonly",
"yuml2svg": "^4.2.1",
"z-schema": "^4.0.2"
},
@ -47,7 +47,7 @@
"@types/js-yaml": "^3.12.1",
"@types/json-pointer": "^1.0.30",
"@types/jsonpath": "^0.2.0",
"@types/lodash": "^4.14.123",
"@types/lodash": "4.14.123",
"@types/md5-file": "^4.0.0",
"@types/node": "^10.12.18",
"@types/request": "^2.48.1",
@ -62,7 +62,7 @@
"tslint": "^5.16.0",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.0.1",
"typescript": "^3.4.5"
"typescript": "~3.4.5"
},
"homepage": "https://github.com/azure/oav",
"repository": {

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,67 @@
{
"parameters": {
"api-version": "2017-04-02",
"subscriptionId": "subid",
"resourceGroupName": "RG",
"profileName": "profile1",
"profile": {
"location": "WestCentralUs",
"sku": {
"name": "Standard_Verizon"
},
"properties": {
"provisioningState": "Creating"
}
}
},
"responses": {
"200": {
"body": {
"name": "profile1",
"id": "/subscriptions/subid/resourcegroups/RG/providers/Microsoft.Cdn/profiles/profile1",
"type": "Microsoft.Cdn/profiles",
"tags": {},
"location": "WestCentralUs",
"sku": {
"name": "Standard_Verizon"
},
"properties": {
"provisioningState": "Creating",
"resourceState": "Creating"
}
}
},
"201": {
"body": {
"name": "profile1",
"id": "/subscriptions/subid/resourcegroups/RG/providers/Microsoft.Cdn/profiles/profile1",
"type": "Microsoft.Cdn/profiles",
"tags": {},
"location": "WestCentralUs",
"sku": {
"name": "Standard_Verizon"
},
"properties": {
"provisioningState": "Creating",
"resourceState": "Creating"
}
}
},
"202": {
"body": {
"name": "profile1",
"id": "/subscriptions/subid/resourcegroups/RG/providers/Microsoft.Cdn/profiles/profile1",
"type": "Microsoft.Cdn/profiles",
"tags": {},
"location": "WestCentralUs",
"sku": {
"name": "Standard_Verizon"
},
"properties": {
"provisioningState": "Creating",
"resourceState": "Creating"
}
}
}
}
}

Просмотреть файл

@ -0,0 +1,35 @@
{
"parameters": {
"api-version": "2017-04-02",
"subscriptionId": "subid",
"resourceGroupName": "RG",
"profileName": "profile1",
"profile": {
"location": "WestCentralUs",
"sku": {
"name": "Standard_Verizon"
},
"properties": {
"provisioningState": 5
}
}
},
"responses": {
"200": {
"body": {
"name": "profile1",
"id": "/subscriptions/subid/resourcegroups/RG/providers/Microsoft.Cdn/profiles/profile1",
"type": "Microsoft.Cdn/profiles",
"tags": {},
"location": "WestCentralUs",
"sku": {
"name": "Standard_Verizon"
},
"properties": {
"provisioningState": "Creating",
"resourceState": "Creating"
}
}
}
}
}

Просмотреть файл

@ -0,0 +1,48 @@
import * as assert from "assert"
import * as validate from "../lib/validate"
const specPath = `test/modelValidation/swaggers/specification/validateReadOnly/cdn.json`
describe("Read Only properties", () => {
it("should throw the error with correct code and message", async () => {
const result = await validate.validateExamples(specPath, "Profiles_Create", {
consoleLogLevel: "off"
})
assert.strictEqual(
result.length,
1,
`swagger "${specPath}" with operation should contain 1 model validation errors.`
)
assert.strictEqual(
result[0].code === "READONLY_PROPERTY_NOT_ALLOWED_IN_REQUEST",
true,
`swagger "${specPath}" should throw an error with code READONLY_PROPERTY_NOT_ALLOWED_IN_REQUEST`
)
assert.equal(
'ReadOnly property `"provisioningState": "Creating"`, cannot be sent in the request.',
result[0].details!.message
)
})
it("should throw 2 errors - readonly properties not allowed in request and invalid type", async () => {
const result = await validate.validateExamples(specPath, "Profiles_Update", {
consoleLogLevel: "off"
})
assert.strictEqual(
result.length,
2,
`swagger "${specPath}" with operation should contain 2 model validation errors.`
)
assert.strictEqual(
result[0].code === "READONLY_PROPERTY_NOT_ALLOWED_IN_REQUEST",
true,
`swagger "${specPath}" should throw an error with code READONLY_PROPERTY_NOT_ALLOWED_IN_REQUEST`
)
assert.strictEqual(
result[1].code === "INVALID_TYPE",
true,
`swagger "${specPath}" should throw an error with code READONLY_PROPERTY_NOT_ALLOWED_IN_REQUEST`
)
})
})