data:
    files:
        -
            _id: { "$oid" : "000000000000000000000001" }
            length: 0
            chunkSize: 4
            uploadDate: { "$date" : "1970-01-01T00:00:00.000Z" }
            md5: "d41d8cd98f00b204e9800998ecf8427e"
            filename: "length-0"
            contentType: "application/octet-stream"
            aliases: []
            metadata: {}
        -
            _id: { "$oid" : "000000000000000000000002" }
            length: 0
            chunkSize: 4
            uploadDate: { "$date" : "1970-01-01T00:00:00.000Z" }
            md5: "d41d8cd98f00b204e9800998ecf8427e"
            filename: "length-0-with-empty-chunk"
            contentType: "application/octet-stream"
            aliases: []
            metadata: {}
        -
            _id: { "$oid" : "000000000000000000000003" }
            length: 2
            chunkSize: 4
            uploadDate: { "$date" : "1970-01-01T00:00:00.000Z" }
            md5: "c700ed4fdb1d27055aa3faa2c2432283"
            filename: "length-2"
            contentType: "application/octet-stream"
            aliases: []
            metadata: {}
        -
            _id: { "$oid" : "000000000000000000000004" }
            length: 8
            chunkSize: 4
            uploadDate: { "$date" : "1970-01-01T00:00:00.000Z" }
            md5: "dd254cdc958e53abaa67da9f797125f5"
            filename: "length-8"
            contentType: "application/octet-stream"
            aliases: []
            metadata: {}
    chunks:
        - { _id : { "$oid" : "000000000000000000000001" }, files_id : { "$oid" : "000000000000000000000002" }, n : 0, data : { $hex : "" } }
        - { _id : { "$oid" : "000000000000000000000002" }, files_id : { "$oid" : "000000000000000000000003" }, n : 0, data : { $hex : "1122" } }
        - { _id : { "$oid" : "000000000000000000000003" }, files_id : { "$oid" : "000000000000000000000004" }, n : 0, data : { $hex : "11223344" } }
        - { _id : { "$oid" : "000000000000000000000004" }, files_id : { "$oid" : "000000000000000000000004" }, n : 1, data : { $hex : "55667788" } }

tests:
    -
        description: "Delete when length is 0"
        act:
            operation: delete
            arguments:
                id: { "$oid" : "000000000000000000000001" }
        assert:
            result: void
            data:
                -
                    { delete : "expected.files", deletes : [
                        { q : { _id : { "$oid" : "000000000000000000000001" } }, limit : 1 }
                    ] }                           
    -
        description: "Delete when length is 0 and there is one extra empty chunk"
        act:
            operation: delete
            arguments:
                id: { "$oid" : "000000000000000000000002" }
        assert:
            result: void
            data:
                -
                    { delete : "expected.files", deletes : [
                        { q : { _id : { "$oid" : "000000000000000000000002" } }, limit : 1 }
                    ] }
                -
                    { delete : "expected.chunks", deletes : [
                        { q : { files_id : { "$oid" : "000000000000000000000002" } }, limit : 0 }
                    ] }
    -
        description: "Delete when length is 8"
        act:
            operation: delete
            arguments:
                id: { "$oid" : "000000000000000000000004" }
        assert:
            result: void
            data:
                -
                    { delete : "expected.files", deletes : [
                        { q : { _id : { "$oid" : "000000000000000000000004" } }, limit : 1 }
                    ] }
                -
                    { delete : "expected.chunks", deletes : [
                        { q : { files_id : { "$oid" : "000000000000000000000004" } }, limit : 0 }
                    ] }
    -
        description: "Delete when files entry does not exist"
        act:
            operation: delete
            arguments:
                id: { "$oid" : "000000000000000000000000" }
        assert:
            error: "FileNotFound"
    -
        description: "Delete when files entry does not exist and there are orphaned chunks"
        arrange:
            data:
                -
                    { delete : "fs.files", deletes : [
                        { q : { _id : { "$oid" : "000000000000000000000004" } }, limit : 1 }
                    ] }
        act:
            operation: delete
            arguments:
                id: { "$oid" : "000000000000000000000004" }
        assert:
            error: "FileNotFound"
            data:
                -
                    { delete : "expected.files", deletes : [
                        { q : { _id : { "$oid" : "000000000000000000000004" } }, limit : 1 }
                    ] }
