Skip to content

Commit

Permalink
tests: fix wording of req.accepts* test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Feb 2, 2022
1 parent 20047bb commit 215f484
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 82 deletions.
34 changes: 18 additions & 16 deletions test/req.acceptsEncoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,35 @@ var express = require('../')

describe('req', function(){
describe('.acceptsEncoding', function(){
it('should be true if encoding accepted', function(done){
it('should return encoding if accepted', function (done) {
var app = express();

app.use(function(req, res){
req.acceptsEncoding('gzip').should.be.ok()
req.acceptsEncoding('deflate').should.be.ok()
res.end();
});
app.get('/', function (req, res) {
res.send({
gzip: req.acceptsEncoding('gzip'),
deflate: req.acceptsEncoding('deflate')
})
})

request(app)
.get('/')
.set('Accept-Encoding', ' gzip, deflate')
.expect(200, done);
.get('/')
.set('Accept-Encoding', ' gzip, deflate')
.expect(200, { gzip: 'gzip', deflate: 'deflate' }, done)
})

it('should be false if encoding not accepted', function(done){
var app = express();

app.use(function(req, res){
req.acceptsEncoding('bogus').should.not.be.ok()
res.end();
});
app.get('/', function (req, res) {
res.send({
bogus: req.acceptsEncoding('bogus')
})
})

request(app)
.get('/')
.set('Accept-Encoding', ' gzip, deflate')
.expect(200, done);
.get('/')
.set('Accept-Encoding', ' gzip, deflate')
.expect(200, { bogus: false }, done)
})
})
})
34 changes: 18 additions & 16 deletions test/req.acceptsEncodings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,35 @@ var express = require('../')

describe('req', function(){
describe('.acceptsEncodings', function () {
it('should be true if encoding accepted', function(done){
it('should return encoding if accepted', function (done) {
var app = express();

app.use(function(req, res){
req.acceptsEncodings('gzip').should.be.ok()
req.acceptsEncodings('deflate').should.be.ok()
res.end();
});
app.get('/', function (req, res) {
res.send({
gzip: req.acceptsEncoding('gzip'),
deflate: req.acceptsEncoding('deflate')
})
})

request(app)
.get('/')
.set('Accept-Encoding', ' gzip, deflate')
.expect(200, done);
.get('/')
.set('Accept-Encoding', ' gzip, deflate')
.expect(200, { gzip: 'gzip', deflate: 'deflate' }, done)
})

it('should be false if encoding not accepted', function(done){
var app = express();

app.use(function(req, res){
req.acceptsEncodings('bogus').should.not.be.ok()
res.end();
});
app.get('/', function (req, res) {
res.send({
bogus: req.acceptsEncoding('bogus')
})
})

request(app)
.get('/')
.set('Accept-Encoding', ' gzip, deflate')
.expect(200, done);
.get('/')
.set('Accept-Encoding', ' gzip, deflate')
.expect(200, { bogus: false }, done)
})
})
})
53 changes: 28 additions & 25 deletions test/req.acceptsLanguage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,52 @@ var express = require('../')

describe('req', function(){
describe('.acceptsLanguage', function(){
it('should be true if language accepted', function(done){
it('should return language if accepted', function (done) {
var app = express();

app.use(function(req, res){
req.acceptsLanguage('en-us').should.be.ok()
req.acceptsLanguage('en').should.be.ok()
res.end();
});
app.get('/', function (req, res) {
res.send({
'en-us': req.acceptsLanguages('en-us'),
en: req.acceptsLanguages('en')
})
})

request(app)
.get('/')
.set('Accept-Language', 'en;q=.5, en-us')
.expect(200, done);
.get('/')
.set('Accept-Language', 'en;q=.5, en-us')
.expect(200, { 'en-us': 'en-us', en: 'en' }, done)
})

it('should be false if language not accepted', function(done){
var app = express();

app.use(function(req, res){
req.acceptsLanguage('es').should.not.be.ok()
res.end();
});
app.get('/', function (req, res) {
res.send({
es: req.acceptsLanguages('es')
})
})

request(app)
.get('/')
.set('Accept-Language', 'en;q=.5, en-us')
.expect(200, done);
.get('/')
.set('Accept-Language', 'en;q=.5, en-us')
.expect(200, { es: false }, done)
})

describe('when Accept-Language is not present', function(){
it('should always return true', function(done){
it('should always return language', function (done) {
var app = express();

app.use(function(req, res){
req.acceptsLanguage('en').should.be.ok()
req.acceptsLanguage('es').should.be.ok()
req.acceptsLanguage('jp').should.be.ok()
res.end();
});
app.get('/', function (req, res) {
res.send({
en: req.acceptsLanguages('en'),
es: req.acceptsLanguages('es'),
jp: req.acceptsLanguages('jp')
})
})

request(app)
.get('/')
.expect(200, done);
.get('/')
.expect(200, { en: 'en', es: 'es', jp: 'jp' }, done)
})
})
})
Expand Down
53 changes: 28 additions & 25 deletions test/req.acceptsLanguages.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,52 @@ var express = require('../')

describe('req', function(){
describe('.acceptsLanguages', function(){
it('should be true if language accepted', function(done){
it('should return language if accepted', function (done) {
var app = express();

app.use(function(req, res){
req.acceptsLanguages('en-us').should.be.ok()
req.acceptsLanguages('en').should.be.ok()
res.end();
});
app.get('/', function (req, res) {
res.send({
'en-us': req.acceptsLanguages('en-us'),
en: req.acceptsLanguages('en')
})
})

request(app)
.get('/')
.set('Accept-Language', 'en;q=.5, en-us')
.expect(200, done);
.get('/')
.set('Accept-Language', 'en;q=.5, en-us')
.expect(200, { 'en-us': 'en-us', en: 'en' }, done)
})

it('should be false if language not accepted', function(done){
var app = express();

app.use(function(req, res){
req.acceptsLanguages('es').should.not.be.ok()
res.end();
});
app.get('/', function (req, res) {
res.send({
es: req.acceptsLanguages('es')
})
})

request(app)
.get('/')
.set('Accept-Language', 'en;q=.5, en-us')
.expect(200, done);
.get('/')
.set('Accept-Language', 'en;q=.5, en-us')
.expect(200, { es: false }, done)
})

describe('when Accept-Language is not present', function(){
it('should always return true', function(done){
it('should always return language', function (done) {
var app = express();

app.use(function(req, res){
req.acceptsLanguages('en').should.be.ok()
req.acceptsLanguages('es').should.be.ok()
req.acceptsLanguages('jp').should.be.ok()
res.end();
});
app.get('/', function (req, res) {
res.send({
en: req.acceptsLanguages('en'),
es: req.acceptsLanguages('es'),
jp: req.acceptsLanguages('jp')
})
})

request(app)
.get('/')
.expect(200, done);
.get('/')
.expect(200, { en: 'en', es: 'es', jp: 'jp' }, done)
})
})
})
Expand Down

0 comments on commit 215f484

Please sign in to comment.