Passed
Push — master ( 198edd...da006d )
by Sergey
04:08 queued 01:46
created

test/fixtures/filters/request.async.filter.ts   A

Complexity

Total Complexity 7
Complexity/F 3.5

Size

Lines of Code 23
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 18
mnd 5
bc 5
fnc 2
dl 0
loc 23
rs 10
bpm 2.5
cpm 3.5
noi 0
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A request.async.filter.ts ➔ getRawHeader 0 8 2
A RequestAsyncFilter.canAsync 0 6 5
1
import { IFilterPermission } from '../../../src';
2
import { Injectable } from '@nestjs/common';
3
4
function getRawHeader(name: string, rawHeaders: string[]): string | boolean {
5
  const key = rawHeaders.indexOf(name);
6
  if (key < 0) {
7
    return false;
8
  }
9
  const value = key + 1;
10
  return rawHeaders[value];
11
}
12
13
@Injectable()
14
export class RequestAsyncFilter implements IFilterPermission {
15
16
  async canAsync(params?: any[]): Promise<boolean> {
17
    const name = 'test-header';
18
    // Fix: missing `headers`, using `rawHeaders` for fixing tests on Node.js 15
19
    const header = params[0]?.headers?.[name] ?? getRawHeader(name, params[0].rawHeaders);
20
    return Promise.resolve(header === 'test');
21
  }
22
}
23