HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/good-life-be/node_modules/express-fileupload/test/isEligibleRequest.spec.js
'use strict';

const assert = require('assert');
const isEligibleRequest = require('../lib/isEligibleRequest');

describe('isEligibleRequest function tests', () => {
  it('should return true if the request method is POST & headers set', () => {
    const req = {
      method: 'POST',
      headers: {
        'content-length': '768751',
        'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryz2D47BnVMA7w5N36'
      }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, true);
  });
  it('should return true if the request method is PUT & headers set', () => {
    const req = {
      method: 'PUT',
      headers: {
        'content-length': '768751',
        'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryz2D47BnVMA7w5N36'
      }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, true);
  });
  it('should return true if the request method is PATCH & headers set', () => {
    const req = {
      method: 'PATCH',
      headers: {
        'content-length': '768751',
        'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryz2D47BnVMA7w5N36'
      }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, true);
  });
  it('should return false if the request method is POST & content length 0', () => {
    const req = {
      method: 'POST',
      headers: {
        'content-length': '0',
        'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryz2D47BnVMA7w5N36'
      }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, false);
  });
  it('should return false if the request method is POST & no content-length', () => {
    const req = {
      method: 'POST',
      headers: {
        'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryz2D47BnVMA7w5N36'
      }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, false);
  });
  it('should return false if the request method is POST & no boundary', () => {
    const req = {
      method: 'POST',
      headers: {
        'content-length': '768751',
        'content-type': 'multipart/form-data; ----WebKitFormBoundaryz2D47BnVMA7w5N36'
      }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, false);
  });
  it('should return false if the request method is not POST, PUT or PATCH', () => {
    const req = {
      method: 'GET',
      headers: {
        'content-length': '768751',
        'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryz2D47BnVMA7w5N36'
      }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, false);
  });
  it('should return false if the request method is not POST, PUT or PATCH', () => {
    const req = {
      method: 'DELETE',
      headers: {
        'content-length': '768751',
        'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryz2D47BnVMA7w5N36'
      }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, false);
  });
  it('should return false if the request method is not POST, PUT or PATCH', () => {
    const req = {
      method: 'OPTIONS',
      headers: {
        'content-length': '768751',
        'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryz2D47BnVMA7w5N36'
      }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, false);
  });
  it('should return false if the request method is not POST, PUT or PATCH', () => {
    const req = {
      method: 'HEAD',
      headers: {
        'content-length': '768751',
        'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryz2D47BnVMA7w5N36'
      }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, false);
  });
  it('should return false if the request is empty or not provided', () => {
    const result = isEligibleRequest();
    assert.equal(result, false);
  });
  it('should return false if content-type is not specified.', () => {
    const req = {
      method: 'POST',
      headers: { 'content-length': '768751' }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, false);
  });
});