@@ -5,22 +5,29 @@ import { Website } from 'entities/website.entity';
55import { mock , mockReset } from 'jest-mock-extended' ;
66import { Repository } from 'typeorm' ;
77import { CoreResultService } from './core-result.service' ;
8+ import { WebsiteService } from '@app/database/websites/websites.service' ;
89import { Logger } from '@nestjs/common' ;
910import { ScanStatus } from 'entities/scan-status' ;
1011
1112describe ( 'CoreResultService' , ( ) => {
1213 let service : CoreResultService ;
1314 let mockRepository : any ;
15+ let mockWebsiteService : any ;
1416
1517 beforeEach ( async ( ) => {
1618 mockRepository = mock < Repository < CoreResult > > ( ) ;
19+ mockWebsiteService = mock < WebsiteService > ( ) ;
1720 const module : TestingModule = await Test . createTestingModule ( {
1821 providers : [
1922 CoreResultService ,
2023 {
2124 provide : getRepositoryToken ( CoreResult ) ,
2225 useValue : mockRepository ,
2326 } ,
27+ {
28+ provide : WebsiteService ,
29+ useValue : mockWebsiteService ,
30+ } ,
2431 ] ,
2532 } ) . compile ( ) ;
2633
@@ -29,6 +36,7 @@ describe('CoreResultService', () => {
2936
3037 afterEach ( async ( ) => {
3138 mockReset ( mockRepository ) ;
39+ mockReset ( mockWebsiteService ) ;
3240 } ) ;
3341
3442 it ( 'should be defined' , ( ) => {
@@ -59,17 +67,6 @@ describe('CoreResultService', () => {
5967 expect ( result ) . toStrictEqual ( coreResult ) ;
6068 } ) ;
6169
62- it ( 'should create a CoreResult' , async ( ) => {
63- const coreResult = new CoreResult ( ) ;
64- const website = new Website ( ) ;
65- website . id = 1 ;
66- coreResult . id = 1 ;
67- coreResult . website = website ;
68-
69- await service . create ( coreResult ) ;
70- expect ( mockRepository . insert ) . toHaveBeenCalledWith ( coreResult ) ;
71- } ) ;
72-
7370 it ( 'should create a CoreResult from CoreResultPages' , async ( ) => {
7471 const websiteId = 1 ;
7572 const scanStatus : ScanStatus = ScanStatus [ 'Completed' ] ;
@@ -285,5 +282,201 @@ describe('CoreResultService', () => {
285282 websiteUrl ,
286283 ) ;
287284 expect ( mockRepository . insert ) . toHaveBeenCalled ( ) ;
285+ expect ( mockWebsiteService . setFilter ) . not . toHaveBeenCalled ( ) ;
286+ expect ( mockRepository . insert ) . toHaveBeenCalledWith (
287+ expect . objectContaining ( { filter : false } ) ,
288+ ) ;
289+ } ) ;
290+
291+ it ( 'should call setFilter when finalUrlMIMEType is a filtered type' , async ( ) => {
292+ const websiteId = 1 ;
293+ const scanStatus : ScanStatus = ScanStatus [ 'Completed' ] ;
294+ const websiteUrl = 'https://example.gov' ;
295+
296+ const pages = {
297+ base : {
298+ targetUrlBaseDomain : 'example.gov' ,
299+ } ,
300+ notFound : {
301+ status : scanStatus ,
302+ result : {
303+ notFoundScan : { targetUrl404Test : false } ,
304+ } ,
305+ } ,
306+ primary : {
307+ status : scanStatus ,
308+ result : {
309+ urlScan : {
310+ targetUrlRedirects : null ,
311+ finalUrl : null ,
312+ finalUrlIsLive : null ,
313+ finalUrlBaseDomain : null ,
314+ finalUrlWebsite : null ,
315+ finalUrlTopLevelDomain : null ,
316+ finalUrlMIMEType : 'application/json' ,
317+ finalUrlSameDomain : null ,
318+ finalUrlStatusCode : null ,
319+ finalUrlSameWebsite : null ,
320+ finalUrlPageHash : null ,
321+ } ,
322+ dapScan : {
323+ dapDetected : null ,
324+ dapParameters : null ,
325+ dapVersion : '' ,
326+ gaTagIds : '' ,
327+ } ,
328+ seoScan : {
329+ ogTitleFinalUrl : null ,
330+ ogDescriptionFinalUrl : null ,
331+ ogArticlePublishedFinalUrl : null ,
332+ ogArticleModifiedFinalUrl : null ,
333+ mainElementFinalUrl : null ,
334+ canonicalLink : null ,
335+ pageTitle : null ,
336+ metaDescriptionContent : null ,
337+ metaKeywordsContent : null ,
338+ ogImageContent : null ,
339+ ogTypeContent : null ,
340+ ogUrlContent : null ,
341+ htmlLangContent : null ,
342+ hrefLangContent : null ,
343+ dcDateContent : null ,
344+ dcDateCreatedContent : null ,
345+ dctermsCreatedContent : null ,
346+ revisedContent : null ,
347+ lastModifiedContent : null ,
348+ dateContent : null ,
349+ } ,
350+ thirdPartyScan : {
351+ thirdPartyServiceDomains : null ,
352+ thirdPartyServiceCount : null ,
353+ cookieDomains : null ,
354+ thirdPartyServiceUrls : null ,
355+ } ,
356+ cookieScan : { domains : '' } ,
357+ uswdsScan : {
358+ usaClasses : null ,
359+ usaClassesUsed : null ,
360+ uswdsString : null ,
361+ uswdsInlineCss : null ,
362+ uswdsUsFlag : null ,
363+ uswdsStringInCss : null ,
364+ uswdsUsFlagInCss : null ,
365+ uswdsPublicSansFont : null ,
366+ uswdsSemanticVersion : null ,
367+ uswdsVersion : null ,
368+ uswdsCount : null ,
369+ heresHowYouKnowBanner : null ,
370+ } ,
371+ loginScan : { loginDetected : null , loginProvider : null } ,
372+ cmsScan : { cms : null } ,
373+ requiredLinksScan : {
374+ requiredLinksUrl : null ,
375+ requiredLinksText : null ,
376+ } ,
377+ searchScan : { searchDetected : null , searchgov : null } ,
378+ mobileScan : { viewportMetaTag : false } ,
379+ toolingScan : { tooling : null } ,
380+ } ,
381+ } ,
382+ robotsTxt : {
383+ status : scanStatus ,
384+ result : {
385+ robotsTxtScan : {
386+ robotsTxtFinalUrl : null ,
387+ robotsTxtStatusCode : null ,
388+ robotsTxtFinalUrlLive : null ,
389+ robotsTxtDetected : null ,
390+ robotsTxtFinalUrlMimeType : null ,
391+ robotsTxtTargetUrlRedirects : null ,
392+ robotsTxtFinalUrlSize : null ,
393+ robotsTxtCrawlDelay : null ,
394+ robotsTxtSitemapLocations : null ,
395+ } ,
396+ } ,
397+ } ,
398+ sitemapXml : {
399+ status : scanStatus ,
400+ result : {
401+ sitemapXmlScan : {
402+ sitemapXmlDetected : null ,
403+ sitemapXmlStatusCode : null ,
404+ sitemapXmlFinalUrl : null ,
405+ sitemapXmlFinalUrlLive : null ,
406+ sitemapTargetUrlRedirects : null ,
407+ sitemapXmlFinalUrlFilesize : null ,
408+ sitemapXmlFinalUrlMimeType : null ,
409+ sitemapXmlLastMod : null ,
410+ sitemapXmlPageHash : null ,
411+ sitemapXmlCount : null ,
412+ sitemapXmlPdfCount : null ,
413+ } ,
414+ } ,
415+ } ,
416+ dns : {
417+ status : scanStatus ,
418+ result : { dnsScan : { ipv6 : true , dnsHostname : null } } ,
419+ } ,
420+ accessibility : {
421+ status : scanStatus ,
422+ result : {
423+ accessibilityScan : {
424+ accessibilityResults : '' ,
425+ accessibilityResultsList : '' ,
426+ } ,
427+ } ,
428+ } ,
429+ performance : {
430+ status : scanStatus ,
431+ result : {
432+ performanceScan : {
433+ largestContentfulPaint : null ,
434+ cumulativeLayoutShift : null ,
435+ } ,
436+ } ,
437+ } ,
438+ security : {
439+ status : scanStatus ,
440+ result : { securityScan : { httpsEnforced : null , hsts : null } } ,
441+ } ,
442+ clientRedirect : {
443+ status : scanStatus ,
444+ result : {
445+ clientRedirectScan : {
446+ hasClientRedirect : null ,
447+ usesJsRedirect : null ,
448+ usesMetaRefresh : null ,
449+ } ,
450+ } ,
451+ } ,
452+ www : {
453+ status : scanStatus ,
454+ result : {
455+ wwwScan : {
456+ wwwFinalUrl : null ,
457+ wwwStatusCode : null ,
458+ wwwTitle : null ,
459+ wwwSame : null ,
460+ } ,
461+ } ,
462+ } ,
463+ } ;
464+ const logger = mock < Logger > ( ) ;
465+
466+ await service . createFromCoreResultPages (
467+ websiteId ,
468+ pages ,
469+ logger ,
470+ false ,
471+ 1 ,
472+ 1 ,
473+ websiteUrl ,
474+ ) ;
475+
476+ expect ( mockRepository . insert ) . toHaveBeenCalled ( ) ;
477+ expect ( mockWebsiteService . setFilter ) . toHaveBeenCalledWith ( websiteId , true ) ;
478+ expect ( mockRepository . insert ) . toHaveBeenCalledWith (
479+ expect . objectContaining ( { filter : true } ) ,
480+ ) ;
288481 } ) ;
289482} ) ;
0 commit comments