Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/1.0/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Generator.prototype.generate = function(cb) {
this.seedRNG();

if (this.format === 'yaml') {
cb(YAML.stringify(json, 4), "yml");
cb(YAML.stringify(json, 4), "yaml");
} else if (this.format === 'xml') {
cb(js2xmlparser('user', json), "xml");
} else if (this.format === 'prettyjson' || this.format === 'pretty') {
Expand Down
11 changes: 7 additions & 4 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ function genUser(req, res, version) {
res.setHeader('Content-disposition', 'attachment; filename=download.' + ext);
fs.writeFileSync(name, output, 'utf8');
} else {

if (ext === 'json'){
if (ext === 'json') {
res.setHeader('Content-Type', 'application/json');
}else if (ext === 'xml'){
} else if (ext === 'xml') {
res.setHeader('Content-Type', 'text/xml');
}else{
} else if (ext === 'yaml') {
res.setHeader('Content-Type', 'text/x-yaml');
} else if (ext === 'csv') {
res.setHeader('Content-Type', 'text/csv');
} else {
res.setHeader('Content-Type', 'text/plain');
}
}
Expand Down
44 changes: 44 additions & 0 deletions spec/randomuserTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,50 @@ describe('Randomuser.me', () => {
} catch(e) {}
});
});

describe('MIME type testing', () => {
it('should return content type application/json when no format specified', (done) => {
request(server).get('/api').expect('Content-Type', /application\/json/)
.end((err, res) => {
if (!err) done();
});
});

it('should return content type application/json when JSON format specified', (done) => {
request(server).get('/api/?fmt=json').expect('Content-Type', /application\/json/)
.end((err, res) => {
if (!err) done();
});
});

it('should return content type application/json when pretty format specified', (done) => {
request(server).get('/api/?fmt=pretty').expect('Content-Type', /application\/json/)
.end((err, res) => {
if (!err) done();
});
});

it('should return content type text/xml when XML format specified', (done) => {
request(server).get('/api/?fmt=xml').expect('Content-Type', /text\/xml/)
.end((err, res) => {
if (!err) done();
});
});

it('should return content type text/x-yaml when YAML format specified', (done) => {
request(server).get('/api/?fmt=yaml').expect('Content-Type', /text\/x\-yaml/)
.end((err, res) => {
if (!err) done();
});
});

it('should return content type text/csv when CSV format specified', (done) => {
request(server).get('/api/?fmt=csv').expect('Content-Type', /text\/csv/)
.end((err, res) => {
if (!err) done();
});
});
});
});
});
});