1 | var t = require('../test-lib/test.js');
|
2 | var assert = require('assert');
|
3 |
|
4 | var apos;
|
5 |
|
6 | describe('Video Field', function() {
|
7 |
|
8 | after(function(done) {
|
9 | return t.destroy(apos, done);
|
10 | });
|
11 |
|
12 | this.timeout(t.timeout);
|
13 |
|
14 | it('should be a property of the apos object', function(done) {
|
15 |
|
16 | apos = require('../index.js')({
|
17 | root: module,
|
18 | shortName: 'test',
|
19 |
|
20 | modules: {
|
21 | 'apostrophe-express': {
|
22 | port: 7900
|
23 | }
|
24 | },
|
25 | afterInit: function(callback) {
|
26 | assert(apos.videoFields);
|
27 |
|
28 |
|
29 |
|
30 | apos.argv._ = [];
|
31 | return callback(null);
|
32 | },
|
33 | afterListen: function(err) {
|
34 | assert(!err);
|
35 | done();
|
36 | }
|
37 | });
|
38 | });
|
39 |
|
40 | it('schema field should accept a valid video', function(done) {
|
41 | var req = apos.tasks.getReq();
|
42 | var object = {
|
43 | url: 'https://www.youtube.com/watch?v=mrVSt0pbo1g&t=38s',
|
44 | title: 'Simpsons: The PTA Has Disbanded!',
|
45 | thumbnail: 'http://youtube.com/imaginary-thumbnail.png'
|
46 | };
|
47 | var schema = [
|
48 | {
|
49 | name: 'video',
|
50 | type: 'video'
|
51 | }
|
52 | ];
|
53 | var output = {};
|
54 | apos.schemas.convert(
|
55 | req,
|
56 | schema,
|
57 | 'form',
|
58 | {
|
59 | video: object
|
60 | },
|
61 | output,
|
62 | function(err) {
|
63 | assert(!err);
|
64 | assert(output.video.url === 'https://www.youtube.com/watch?v=mrVSt0pbo1g&t=38s');
|
65 | done();
|
66 | }
|
67 | );
|
68 | });
|
69 |
|
70 | it('schema field should not panic if video is absent', function(done) {
|
71 | var req = apos.tasks.getReq();
|
72 | var schema = [
|
73 | {
|
74 | name: 'video',
|
75 | type: 'video'
|
76 | }
|
77 | ];
|
78 | var output = {};
|
79 | apos.schemas.convert(
|
80 | req,
|
81 | schema,
|
82 | 'form',
|
83 | {},
|
84 | output,
|
85 | function(err) {
|
86 | assert(!err);
|
87 | assert(!output.video);
|
88 | done();
|
89 | }
|
90 | );
|
91 | });
|
92 |
|
93 | it('schema field should complain if video is absent and required', function(done) {
|
94 | var req = apos.tasks.getReq();
|
95 | var schema = [
|
96 | {
|
97 | name: 'video',
|
98 | type: 'video',
|
99 | required: true
|
100 | }
|
101 | ];
|
102 | var output = {};
|
103 | apos.schemas.convert(
|
104 | req,
|
105 | schema,
|
106 | 'form',
|
107 | {},
|
108 | output,
|
109 | function(err) {
|
110 | assert(err);
|
111 | assert(err === 'video.required');
|
112 | assert(!output.video);
|
113 | done();
|
114 | }
|
115 | );
|
116 | });
|
117 |
|
118 | });
|