Merged PR 22705: adding tileLoadConfiguration

adding tileLoadConfiguration to models
This commit is contained in:
Omri Armstrong 2017-08-09 09:03:04 +00:00
Родитель 008962f139
Коммит 899d87bee3
4 изменённых файлов: 240 добавлений и 1 удалений

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

@ -1,6 +1,6 @@
{
"name": "powerbi-models",
"version": "0.11.3",
"version": "0.11.4",
"description": "Contains JavaScript & TypeScript object models for Microsoft Power BI JavaScript SDK. For each model there is a TypeScript interface, a json schema definitions, and a validation function to ensure and object is valid.",
"main": "dist/models.js",
"typings": "dist/models.d.ts",

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

@ -5,6 +5,7 @@ export const advancedFilterSchema = require('./schemas/advancedFilter.json');
export const filterSchema = require('./schemas/filter.json');
export const loadSchema = require('./schemas/reportLoadConfiguration.json');
export const dashboardLoadSchema = require('./schemas/dashboardLoadConfiguration.json');
export const tileLoadSchema = require('./schemas/tileLoadConfiguration.json');
export const pageSchema = require('./schemas/page.json');
export const settingsSchema = require('./schemas/settings.json');
export const basicFilterSchema = require('./schemas/basicFilter.json');
@ -113,6 +114,17 @@ export interface IDashboardLoadConfiguration {
export const validateDashboardLoad = validate(dashboardLoadSchema);
export interface ITileLoadConfiguration {
accessToken: string;
id: string;
dashboardId: string;
tokenType?: TokenType;
width?: number;
height?: number;
}
export const validateTileLoad = validate(tileLoadSchema);
export interface IReport {
id: string;
displayName: string;

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

@ -0,0 +1,50 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"accessToken": {
"type": "string",
"messages": {
"type": "accessToken must be a string",
"required": "accessToken is required"
}
},
"id": {
"type": "string",
"messages": {
"type": "id must be a string",
"required": "id is required"
}
},
"dashboardId": {
"type": "string",
"messages": {
"type": "dashboardId must be a string",
"required": "dashboardId is required"
}
},
"tokenType": {
"type": "number",
"enum": [0, 1],
"default": 0,
"invalidMessage": "tokenType property is invalid"
},
"width": {
"type": "number",
"messages": {
"type": "width must be a number"
}
},
"height": {
"type": "number",
"messages": {
"type": "height must be a number"
}
}
},
"required": [
"accessToken",
"id",
"dashboardId"
]
}

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

@ -460,6 +460,183 @@ describe('Unit | Models', function () {
});
});
describe('validateTileLoad', function () {
const accessTokenRequiredMessage = models.tileLoadSchema.properties.accessToken.messages.required;
const accessTokenInvalidTypeMessage = models.tileLoadSchema.properties.accessToken.messages.type;
const idRequiredMessage = models.tileLoadSchema.properties.id.messages.required;
const idInvalidTypeMessage = models.tileLoadSchema.properties.id.messages.type;
const dashboardIdRequiredMessage = models.tileLoadSchema.properties.dashboardId.messages.required;
const dashboardIdInvalidTypeMessage = models.tileLoadSchema.properties.dashboardId.messages.type;
const widthITypeMessage = models.tileLoadSchema.properties.width.messages.type;
const heightITypeMessage = models.tileLoadSchema.properties.height.messages.type;
it(`should return errors with one containing message '${accessTokenRequiredMessage}' if accessToken is not defined`, function () {
// Arrange
const testData = {
load: {
}
};
// Act
const errors = models.validateTileLoad(testData.load);
// Assert
testForExpectedMessage(errors, accessTokenRequiredMessage);
});
it(`should return errors with one containing message '${accessTokenInvalidTypeMessage}' if accessToken is not a string`, function () {
// Arrange
const testData = {
load: {
accessToken: 1
}
};
// Act
const errors = models.validateTileLoad(testData.load);
// Assert
testForExpectedMessage(errors, accessTokenInvalidTypeMessage);
});
it(`should return errors with one containing message '${idRequiredMessage}' if id is not defined`, function () {
// Arrange
const testData = {
load: {
accessToken: "fakeToken"
}
};
// Act
const errors = models.validateTileLoad(testData.load);
// Assert
testForExpectedMessage(errors, idRequiredMessage);
});
it(`should return errors with one containing message '${idInvalidTypeMessage}' if id is not a string`, function () {
// Arrange
const testData = {
load: {
accessToken: 'fakeAccessToken',
id: 1
}
};
// Act
const errors = models.validateTileLoad(testData.load);
// Assert
testForExpectedMessage(errors, idInvalidTypeMessage);
});
it(`should return errors with one containing message '${dashboardIdRequiredMessage}' if dashboard id is not defined`, function () {
// Arrange
const testData = {
load: {
accessToken: "fakeToken",
id: "fakeId"
}
};
// Act
const errors = models.validateTileLoad(testData.load);
// Assert
testForExpectedMessage(errors, dashboardIdRequiredMessage);
});
it(`should return errors with one containing message '${dashboardIdInvalidTypeMessage}' if dashboard id is not a string`, function () {
// Arrange
const testData = {
load: {
accessToken: 'fakeAccessToken',
id: 'fakeId',
dashboardId: 1
}
};
// Act
const errors = models.validateTileLoad(testData.load);
// Assert
testForExpectedMessage(errors, dashboardIdInvalidTypeMessage);
});
it(`should return undefined if id, dashboardId and accessToken are provided`, function () {
// Arrange
const testData = {
load: {
id: 'fakeId',
accessToken: 'fakeAccessToken',
dashboardId: 'fakeDashboardId'
}
};
// Act
const errors = models.validateTileLoad(testData.load);
// Assert
expect(errors).toBeUndefined();
});
it(`should return undefined if id, dashboardId, height, width, tokenType, filter and accessToken are provided`, function () {
// Arrange
const testData = {
load: {
id: 'fakeId',
dashboardId: 'fakeDashboardId',
height: 1,
width: 2,
tokenType: 0,
accessToken: 'fakeAccessToken',
}
};
// Act
const errors = models.validateTileLoad(testData.load);
// Assert
expect(errors).toBeUndefined();
});
it(`should return errors with one containing message '${widthITypeMessage}' if width is not a number`, function () {
// Arrange
const testData = {
load: {
accessToken: 'fakeAccessToken',
id: 'fakeId',
dashboardId: 'fakeDashboardId',
width: 'two',
}
};
// Act
const errors = models.validateTileLoad(testData.load);
// Assert
testForExpectedMessage(errors, widthITypeMessage);
});
it(`should return errors with one containing message '${heightITypeMessage}' if height is not a number`, function () {
// Arrange
const testData = {
load: {
accessToken: 'fakeAccessToken',
id: 'fakeId',
dashboardId: 'fakeDashboardId',
height: '2',
}
};
// Act
const errors = models.validateTileLoad(testData.load);
// Assert
testForExpectedMessage(errors, heightITypeMessage);
});
});
describe('validateFilter', function () {
it("should return errors if object does not validate against schema", function () {
// Arrange