<commit_before>fixtures = require './fixtures/data'
fs = require 'fs'
helpers = require './helpers'
expect = require('chai').expect

describe 'Write operations', ->

    before helpers.clearDb

    before helpers.startServer
    before helpers.makeTestClient
    after  helpers.killServer

    describe 'Create Album - POST /albums', ->

        album =
            description: "mydescription"
            title: "mytitle"

        it 'should allow requests', (done) ->
            @client.post 'albums', album, done

        it 'should reply with the created album', ->
            expect(@body.description).to.equal album.description
            expect(@body.title).to.equal album.title
            expect(@body.id).to.exist
            @albumid = @body.id


    describe 'Create Album with multiline title - POST /albums', ->

        album =
            title: "mytitle<div><br></div>"

        it 'should reply with the created album with a sanitized title', ->
            expect(@body.title).to.equal 'mytitle'


    describe 'Create Photo - POST /photos', ->

        raw = "./tests/fixtures/test.jpg"
        screen = "./tests/fixtures/screen.jpg"
        thumb = "./tests/fixtures/thumb.jpg"

        it "should allow request", (done) ->
            @timeout 6000
            req = @client.post "photos", null, done
            form = req.form()
            form.append 'title', 'phototitle'
            form.append 'albumid', @albumid
            form.append 'raw', fs.createReadStream(raw)
            form.append 'screen', fs.createReadStream(screen)
            form.append 'thumb', fs.createReadStream(thumb)

        it 'should reply with the created photo', ->
            expect(@body.title).to.equal 'phototitle'
            @photoid = @body.id


    describe 'Update Album - PUT /albums/:id', ->

        update =
            description: "newdescription"
            title: "newtitle"
            id: @albumid

        it 'should allow requests', (done) ->
            @client.put "albums/#{@albumid}", update, done

        it 'should reply with the updated album', ->
            expect(@body.description).to.equal 'newdescription'
            expect(@body.title).to.equal 'newtitle'
            expect(@body.id).to.exist

        it 'when I GET the album', (done) ->
            @client.get "albums/#{@albumid}", done

        it 'then it is changed', ->
            expect(@body.description).to.equal 'newdescription'


    describe 'Update Album with multiline title - POST /albums', ->

        update =
            title: "newtitle<div><br></div>"
            id: @albumid

        it 'should reply with the updated album with a sanitized title', ->
            expect(@body.title).to.equal 'newtitle'

        it 'when I GET the album', (done) ->
            @client.get "albums/#{@albumid}", done

        it 'then it is changed', ->
            expect(@body.title).to.equal 'newtitle'


    describe 'Update Photo - PUT /photos/:id', ->

        update =
            title: 'newtitle'

        it 'should allow requests', (done) ->
            @client.put "photos/#{@photoid}", update, done

        it 'should reply with the updated photo', ->
            expect(@body.title).to.equal 'newtitle'

        it 'should have keeped its attachements', ->
            expect(@body._attachments.raw).to.exist
            expect(@body._attachments.thumb).to.exist


    describe 'Delete Photo - DELETE /photos/:id', ->

        it 'should allow requests', (done) ->
            @client.del "photos/#{@photoid}", done

        it 'should reply with nothing', ->
            expect(@body.success).to.be.ok
<commit_msg>fix broken tests about attachments<commit_after>fixtures = require './fixtures/data'
fs = require 'fs'
helpers = require './helpers'
expect = require('chai').expect

describe 'Write operations', ->

    before helpers.clearDb

    before helpers.startServer
    before helpers.makeTestClient
    after  helpers.killServer

    describe 'Create Album - POST /albums', ->

        album =
            description: "mydescription"
            title: "mytitle"

        it 'should allow requests', (done) ->
            @client.post 'albums', album, done

        it 'should reply with the created album', ->
            expect(@body.description).to.equal album.description
            expect(@body.title).to.equal album.title
            expect(@body.id).to.exist
            @albumid = @body.id


    describe 'Create Album with multiline title - POST /albums', ->

        album =
            title: "mytitle<div><br></div>"

        it 'should reply with the created album with a sanitized title', ->
            expect(@body.title).to.equal 'mytitle'


    describe 'Create Photo - POST /photos', ->

        raw = "./tests/fixtures/test.jpg"
        screen = "./tests/fixtures/screen.jpg"
        thumb = "./tests/fixtures/thumb.jpg"

        it "should allow request", (done) ->
            @timeout 6000
            req = @client.post "photos", null, done
            form = req.form()
            form.append 'title', 'phototitle'
            form.append 'albumid', @albumid
            form.append 'raw', fs.createReadStream(raw)
            form.append 'screen', fs.createReadStream(screen)
            form.append 'thumb', fs.createReadStream(thumb)

        it 'should reply with the created photo', ->
            expect(@body.title).to.equal 'phototitle'
            @photoid = @body.id


    describe 'Update Album - PUT /albums/:id', ->

        update =
            description: "newdescription"
            title: "newtitle"
            id: @albumid

        it 'should allow requests', (done) ->
            @client.put "albums/#{@albumid}", update, done

        it 'should reply with the updated album', ->
            expect(@body.description).to.equal 'newdescription'
            expect(@body.title).to.equal 'newtitle'
            expect(@body.id).to.exist

        it 'when I GET the album', (done) ->
            @client.get "albums/#{@albumid}", done

        it 'then it is changed', ->
            expect(@body.description).to.equal 'newdescription'


    describe 'Update Album with multiline title - POST /albums', ->

        update =
            title: "newtitle<div><br></div>"
            id: @albumid

        it 'should reply with the updated album with a sanitized title', ->
            expect(@body.title).to.equal 'newtitle'

        it 'when I GET the album', (done) ->
            @client.get "albums/#{@albumid}", done

        it 'then it is changed', ->
            expect(@body.title).to.equal 'newtitle'


    describe 'Update Photo - PUT /photos/:id', ->

        update =
            title: 'newtitle'

        it 'should allow requests', (done) ->
            @client.put "photos/#{@photoid}", update, done

        it 'should reply with the updated photo', ->
            expect(@body.title).to.equal 'newtitle'

        it 'should have keeped its attachements', ->
            expect(@body.binary.raw).to.exist
            expect(@body.binary.thumb).to.exist


    describe 'Delete Photo - DELETE /photos/:id', ->

        it 'should allow requests', (done) ->
            @client.del "photos/#{@photoid}", done

        it 'should reply with nothing', ->
            expect(@body.success).to.be.ok

{'fraction_non_alphanumeric': 0.13029762721163077, 'fraction_numerical': 0.001097243176518996, 'mean_word_length': 1.9582150101419877, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2713404', 'n_tokens_mistral': 2076, 'n_tokens_neox': 1968, 'n_words': 556}