1 | request = require 'supertest'
|
2 | fs = require 'fs'
|
3 | server = require '..'
|
4 | path = require 'path'
|
5 | random = require '../lib/random_id'
|
6 | testid = random()
|
7 | argv = require('../lib/defaultargs.coffee')({data: path.join('/tmp', 'sfwtests', testid), port: 55556, security_legacy: true})
|
8 |
|
9 | describe 'sitemap', ->
|
10 | app = {}
|
11 | before((done) ->
|
12 | app = server(argv)
|
13 | app.once("owner-set", ->
|
14 | app.listen app.startOpts.port, app.startOpts.host, done
|
15 | ))
|
16 |
|
17 |
|
18 | request = request('http://localhost:55556')
|
19 |
|
20 |
|
21 | sitemapLoc = path.join('/tmp', 'sfwtests', testid, 'status', 'sitemap.json')
|
22 |
|
23 | it 'new site should have an empty sitemap', (done) ->
|
24 | request
|
25 | .get('/system/sitemap.json')
|
26 | .expect(200)
|
27 | .expect('Content-Type', /json/)
|
28 | .end (err, res) ->
|
29 | if err
|
30 | throw err
|
31 | res.body.should.be.empty
|
32 | done()
|
33 |
|
34 | it 'creating a page should add it to the sitemap', (done) ->
|
35 | body = JSON.stringify({
|
36 | type: 'create'
|
37 | item: {
|
38 | title: "Asdf Test Page"
|
39 | story: [
|
40 | {id: "a1", type: "paragraph", text: "this is the first paragraph"}
|
41 | {id: "a2", type: "paragraph", text: "this is the second paragraph"}
|
42 | {id: "a3", type: "paragraph", text: "this is the third paragraph"}
|
43 | {id: "a4", type: "paragraph", text: "this is the fourth paragraph"}
|
44 | ]
|
45 | }
|
46 | date: 1234567890123
|
47 | })
|
48 |
|
49 | request
|
50 | .put('/page/adsf-test-page/action')
|
51 | .send("action=" + body)
|
52 | .expect(200)
|
53 | .end (err, res) ->
|
54 | if err
|
55 | throw err
|
56 |
|
57 | app.sitemaphandler.once 'finished', ->
|
58 | try
|
59 | sitemap = JSON.parse(fs.readFileSync(sitemapLoc))
|
60 | catch err
|
61 | throw err
|
62 | sitemap[0].slug.should.equal['adsf-test-page']
|
63 | sitemap[0].synopsis.should.equal['this is the first paragraph']
|
64 | done()
|
65 |
|
66 | it 'synopsis should reflect edit to first paragraph', (done) ->
|
67 | body = JSON.stringify({
|
68 | type: 'edit'
|
69 | item: {id: 'a1', type: 'paragraph', text: 'edited'}
|
70 | id: 'a1'
|
71 | })
|
72 |
|
73 | request
|
74 | .put('/page/adsf-test-page/action')
|
75 | .send("action=" + body)
|
76 | .expect(200)
|
77 | .end (err, res) ->
|
78 | if err
|
79 | throw err
|
80 | app.sitemaphandler.once 'finished', ->
|
81 | try
|
82 | sitemap = JSON.parse(fs.readFileSync(sitemapLoc))
|
83 | catch err
|
84 | throw err
|
85 | sitemap[0].slug.should.equal['adsf-test-page']
|
86 | sitemap[0].synopsis.should.equal['edited']
|
87 | done()
|
88 |
|
89 | it 'deleting a page should remove it from the sitemap', (done) ->
|
90 |
|
91 | request
|
92 | .delete('/adsf-test-page.json')
|
93 | .send()
|
94 | .expect(200)
|
95 | .end (err, res) ->
|
96 | if err
|
97 | throw err
|
98 | app.sitemaphandler.once 'finished', ->
|
99 | try
|
100 | sitemap = JSON.parse(fs.readFileSync(sitemapLoc))
|
101 | catch error
|
102 | throw err
|
103 | sitemap.should.be.empty
|
104 | done()
|
105 |
|
106 |
|
107 |
|
108 | after( ->
|
109 | app.close() if app.close)
|