Skip to content

Commit

Permalink
feat(transforms): add pdfinfo and pdfconvert to transforms (#192)
Browse files Browse the repository at this point in the history
* feat(transforms): add pdfinfo and pdfconvert to transforms
  • Loading branch information
pcholuj authored Jan 29, 2019
1 parent 931e5cc commit da62507
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/lib/api/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,14 @@ export interface TransformOptions {
orientation?: EUrlscreenshotOrientation;
device?: string;
} | true;
pdfinfo?: {
colorinfo?: boolean
} | true;
pdfconvert?: {
pageorientation?: string
pageformat?: string
pages?: (string | number)[]
};
}

/**
Expand Down
85 changes: 85 additions & 0 deletions src/schema/transforms.schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,89 @@ describe('Transforms Schema', () => {
}));
});
});

describe('Pdfinfo', () => {
it('should validate correct params with bool value', () => {
assert.ok(validate({
pdfinfo: true,
}));
});

it('should validate correct params with color info', () => {
assert.ok(validate({
pdfinfo: {
colorinfo: true,
},
}));
});
});

describe('Pdfconvert', () => {
describe('Pages', () => {
[[1,2], ['1-', 3], ['-2']].forEach((val) => {
it(`should validate on correct page "${val}"`, () => {
assert.ok(validate({
pdfconvert: {
pages: val,
},
}));
});
});

it('should return error on fail page "1a"', () => {
assertFail(validate({
pdfconvert: {
pages: '1a',
},
}));
});

});

describe('Page orientation', () => {
it('should pass on correct orientation "landscape"', () => {
assert.ok(validate({
pdfconvert: {
pageorientation: 'landscape',
},
}));
});

it('should pass on correct orientation "portrait"', () => {
assert.ok(validate({
pdfconvert: {
pageorientation: 'portrait',
},
}));
});

it('should fail on wrong orientation "landscape1"', () => {
assertFail(validate({
pdfconvert: {
pageorientation: 'landscape1',
},
}));
});
});

describe('Page format', () => {
['a2', 'a3', 'a4', 'a5', 'b4', 'b5', 'letter', 'legal', 'tabloid'].forEach((val) => {
it(`should when correct page format is provided ${val}`, () => {
assert.ok(validate({
pdfconvert: {
pageformat: val,
},
}));
});
});

it('should fail on wrong page format ie a22', () => {
assertFail(validate({
pdfconvert: {
pageformat: 'a22',
},
}));
});
});
});
});
57 changes: 56 additions & 1 deletion src/schema/transforms.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ export const TransformSchema = {
type: 'object',
additionalProperties: false,
definitions: {
pageFormatDef: {
'$id': '#pageFormatDef',
type: 'string',
enum: ['a2', 'a3', 'a4', 'a5', 'b4', 'b5', 'letter', 'legal', 'tabloid'],
},
pageRangeDef: {
'$id': '#pageRangeDef',
type: 'array',
uniqueItems: true,
items: [{
oneOf: [{
type: 'integer',
minimum: 1,
}, {
type: 'string',
pattern: '^(\\d+(?:-\\d+)?)$|^(-\\d+)$|^(\\d+-)$',
errorMessage: 'Param should be provided in one of the following formats: "1,2,3,5", "1-3", "1-", "-2" ',
}],
}],
},
facesDef: {
'$id': '#facesDef',
oneOf: [{
Expand Down Expand Up @@ -954,7 +974,7 @@ export const TransformSchema = {
},
pageformat: {
type: 'string',
enum: ['a3', 'a4', 'a5', 'b4', 'b5', 'letter', 'legal', 'tabloid'],
enum: ['a2', 'a3', 'a4', 'a5', 'b4', 'b5', 'letter', 'legal', 'tabloid'],
},
pageorientation: {
type: 'string',
Expand Down Expand Up @@ -1256,5 +1276,40 @@ export const TransformSchema = {
},
required: ['policy', 'signature'],
},
pdfinfo: {
oneOf: [{
type: 'boolean',
}, {
type: 'object',
properties: {
colorinfo: {
type: 'boolean',
},
},
}],
},
pdfconvert: {
type: 'object',
additionalProperties: false,
properties: {
pageorientation: {
type: 'string',
enum: ['portrait', 'landscape'],
},
pageformat: {
'$ref': '#pageFormatDef',
},
pages: {
'$ref': '#pageRangeDef',
},
},
oneOf: [{
required: ['pageorientation'],
}, {
required: ['pageformat'],
}, {
required: ['pages'],
}],
},
},
};

0 comments on commit da62507

Please sign in to comment.