1 | var assert = require('assert');
|
2 | var _ = require('@sailshq/lodash');
|
3 | var async = require('async');
|
4 | var request = require('request');
|
5 | var fs = require('fs');
|
6 | const get = require('./lib/get');
|
7 |
|
8 | describe('Apostrophe Sitemap: simple site without workflow', function() {
|
9 |
|
10 | var apos;
|
11 |
|
12 | this.timeout(5000);
|
13 |
|
14 | after(function(done) {
|
15 | try {
|
16 | require('apostrophe/test-lib/util').destroy(apos, done);
|
17 | } catch (e) {
|
18 | console.warn('Old version of apostrophe does not export test-lib/util library, just dropping old test db');
|
19 | apos.db.dropDatabase();
|
20 | setTimeout(done, 1000);
|
21 | }
|
22 | });
|
23 |
|
24 | it('should be a property of the apos object', function(done) {
|
25 | apos = require('apostrophe')({
|
26 | testModule: true,
|
27 | baseUrl: 'http://localhost:7780',
|
28 | modules: {
|
29 | 'apostrophe-express': {
|
30 | port: 7780
|
31 | },
|
32 | 'apostrophe-site-map': {
|
33 | },
|
34 | 'apostrophe-pages': {
|
35 | park: [
|
36 | {
|
37 | title: 'Tab One',
|
38 | type: 'default',
|
39 | slug: '/tab-one',
|
40 | _children: [
|
41 | {
|
42 | title: 'Tab One Child One',
|
43 | type: 'default',
|
44 | slug: '/tab-one/child-one'
|
45 | },
|
46 | {
|
47 | title: 'Tab One Child Two',
|
48 | type: 'default',
|
49 | slug: '/tab-one/child-two'
|
50 | },
|
51 | ]
|
52 | },
|
53 | {
|
54 | title: 'Tab Two',
|
55 | type: 'default',
|
56 | slug: '/tab-two',
|
57 | _children: [
|
58 | {
|
59 | title: 'Tab Two Child One',
|
60 | type: 'default',
|
61 | slug: '/tab-two/child-one'
|
62 | },
|
63 | {
|
64 | title: 'Tab Two Child Two',
|
65 | type: 'default',
|
66 | slug: '/tab-two/child-two'
|
67 | },
|
68 | ]
|
69 | },
|
70 | {
|
71 | title: 'Products',
|
72 | type: 'products-page',
|
73 | slug: '/products'
|
74 | }
|
75 | ],
|
76 | types: [
|
77 | {
|
78 | name: 'home',
|
79 | label: 'Home'
|
80 | },
|
81 | {
|
82 | name: 'default',
|
83 | label: 'Default'
|
84 | },
|
85 | {
|
86 | name: 'products',
|
87 | label: 'Products'
|
88 | }
|
89 | ]
|
90 | },
|
91 | 'products': {
|
92 | extend: 'apostrophe-pieces',
|
93 | name: 'product'
|
94 | },
|
95 | 'products-pages': {
|
96 | extend: 'apostrophe-pieces-pages'
|
97 | },
|
98 | },
|
99 | afterInit: function(callback) {
|
100 | assert(apos.modules['apostrophe-site-map']);
|
101 | return callback(null);
|
102 | },
|
103 | afterListen: function(err) {
|
104 | done();
|
105 | }
|
106 | });
|
107 | });
|
108 |
|
109 | it('insert a product for test purposes', function(done) {
|
110 | var product = _.assign(apos.modules.products.newInstance(), {
|
111 | title: 'Cheese',
|
112 | slug: 'cheese'
|
113 | });
|
114 | apos.modules.products.insert(apos.tasks.getReq(), product, function(err) {
|
115 | assert(!err);
|
116 | done();
|
117 | });
|
118 | });
|
119 |
|
120 | it('make sure everything is published and out of the trash for test purposes', function(done) {
|
121 | return apos.docs.db.update({}, {
|
122 | $set: {
|
123 | trash: false,
|
124 | published: true
|
125 | }
|
126 | }, {
|
127 | multi: true
|
128 | }, function(err, count) {
|
129 | assert(!err);
|
130 | done();
|
131 | });
|
132 | });
|
133 |
|
134 | it('insert an unpublished product for test purposes', function(done) {
|
135 | var product = _.assign(apos.modules.products.newInstance(), {
|
136 | title: 'Rocks',
|
137 | slug: 'rocks',
|
138 | published: false
|
139 | });
|
140 | apos.modules.products.insert(apos.tasks.getReq(), product, function(err) {
|
141 | assert(!err);
|
142 | done();
|
143 | });
|
144 | });
|
145 |
|
146 | it('should generate a suitable sitemap', function(done) {
|
147 | this.timeout(10000);
|
148 | get('http://localhost:7780/sitemap.xml', function(err, xml) {
|
149 | if (err) {
|
150 | console.error(err);
|
151 | }
|
152 | assert(!err);
|
153 | assert(xml);
|
154 | assert(xml.indexOf('<loc>http://localhost:7780/</loc>') !== -1);
|
155 | assert(xml.indexOf('<loc>http://localhost:7780/tab-one</loc>') !== -1);
|
156 | assert(xml.indexOf('<loc>http://localhost:7780/tab-two</loc>') !== -1);
|
157 | assert(xml.indexOf('<loc>http://localhost:7780/tab-one/child-one</loc>') !== -1);
|
158 | assert(xml.indexOf('<loc>http://localhost:7780/products/cheese</loc>') !== -1);
|
159 | assert(xml.indexOf('<loc>http://localhost:7780/products/rocks</loc>') === -1);
|
160 | done();
|
161 | });
|
162 | });
|
163 |
|
164 | });
|