Skip to content
Snippets Groups Projects
Select Git revision
  • 96a93a614626f784a7c33ce6da3f99f07ccf58ab
  • master default protected
  • gh-pages
  • dependabot/npm_and_yarn/neostandard-0.12.2
  • dependabot/npm_and_yarn/eslint-plugin-import-2.32.0
  • dependabot/npm_and_yarn/typescript-eslint/parser-8.36.0
  • dependabot/npm_and_yarn/nock-14.0.5
  • dependabot/npm_and_yarn/react-19.1.0
  • dependabot/npm_and_yarn/react-dom-19.1.0
  • server-2025-02-01-6100669a
  • server-2024-11-01-87cba042
  • server-2024-10-01-6875b7c8
  • dependabot/npm_and_yarn/path-to-regexp-8.2.0
  • server-2024-09-01-3d52575c
  • daily-tests-gha2
  • daily-tests-gha
  • server-2023-12-01-92d8fb8e
  • server-2023-11-01-a80c93fd
  • server-2023-10-01-31096085
  • coc-v2
  • server-2023-09-01-8edc3810
  • server-2025-07-01
  • 5.0.2
  • 5.0.1
  • 5.0.0
  • server-2025-06-01
  • server-2025-05-01
  • server-2025-04-03
  • server-2025-03-02
  • server-2025-03-01
  • server-2025-02-02
  • server-2025-01-01
  • server-2024-12-01
  • server-2024-11-02
  • 4.1.0
  • server-2024-09-25
  • server-2024-09-02
  • server-2024-08-01
  • server-2024-07-01
  • 4.0.0
  • server-2024-06-01
41 results

pub-publisher.tester.js

Blame
  • comment.spec.ts 5.59 KiB
    import { mocked, platform } from '../../../test/util';
    import * as _cache from '../../util/cache/repository';
    import type { RepoCacheData } from '../../util/cache/repository/types';
    import { ensureComment, ensureCommentRemoval } from './comment';
    
    jest.mock('.');
    jest.mock('../../util/cache/repository');
    
    const cache = mocked(_cache);
    
    describe('modules/platform/comment', () => {
      let repoCache: RepoCacheData = {};
    
      beforeEach(() => {
        repoCache = {};
    
        cache.getCache.mockReturnValue(repoCache);
      });
    
      describe('ensureComment', () => {
        it('caches created comment', async () => {
          platform.ensureComment.mockResolvedValueOnce(true);
    
          const res = await ensureComment({
            number: 1,
            topic: 'foo',
            content: 'bar',
          });
    
          expect(res).toBe(true);
          expect(repoCache).toEqual({
            prComments: {
              '1': {
                foo: 'd82c4eb5261cb9c8aa9855edd67d1bd10482f41529858d925094d173fa662aa91ff39bc5b188615273484021dfb16fd8284cf684ccf0fc795be3aa2fc1e6c181',
              },
            },
          });
        });
    
        it('caches comment with no topic', async () => {
          platform.ensureComment.mockResolvedValueOnce(true);
    
          const res = await ensureComment({
            number: 1,
            topic: null,
            content: 'bar',
          });
    
          expect(res).toBe(true);
          expect(repoCache).toEqual({
            prComments: {
              '1': {
                '': 'd82c4eb5261cb9c8aa9855edd67d1bd10482f41529858d925094d173fa662aa91ff39bc5b188615273484021dfb16fd8284cf684ccf0fc795be3aa2fc1e6c181',
              },
            },
          });
        });
    
        it('does not cache failed comment', async () => {
          platform.ensureComment.mockResolvedValueOnce(false);
    
          const res = await ensureComment({
            number: 1,
            topic: 'foo',
            content: 'bar',
          });
    
          expect(res).toBe(false);
          expect(repoCache).toBeEmpty();
        });
    
        it('short-circuits if comment already exists', async () => {
          platform.ensureComment.mockResolvedValue(true);
    
          await ensureComment({ number: 1, topic: 'aaa', content: '111' });
          await ensureComment({ number: 1, topic: 'aaa', content: '111' });
    
          expect(platform.ensureComment).toHaveBeenCalledTimes(1);
        });
    
        it('rewrites content hash', async () => {
          platform.ensureComment.mockResolvedValue(true);
    
          await ensureComment({ number: 1, topic: 'aaa', content: '111' });
          await ensureComment({ number: 1, topic: 'aaa', content: '222' });
    
          expect(platform.ensureComment).toHaveBeenCalledTimes(2);
          expect(repoCache).toEqual({
            prComments: {
              '1': {
                aaa: '5f28f24f5520230fd1e66ea6ac649e9f9637515f516b2ef74fc90622b60f165eafca8f34db8471b85b9b4a2cdf72f75099ae0eb8860c4f339252261778d406eb',
              },
            },
          });
        });
    
        it('caches comments many comments with different topics', async () => {
          platform.ensureComment.mockResolvedValue(true);
    
          await ensureComment({ number: 1, topic: 'aaa', content: '111' });
          await ensureComment({ number: 1, topic: 'aaa', content: '111' });
    
          await ensureComment({ number: 1, topic: 'bbb', content: '111' });
          await ensureComment({ number: 1, topic: 'bbb', content: '111' });
    
          expect(platform.ensureComment).toHaveBeenCalledTimes(2);
          expect(repoCache).toEqual({
            prComments: {
              '1': {
                aaa: 'fb131bc57a477c8c9d068f1ee5622ac304195a77164ccc2d75d82dfe1a727ba8d674ed87f96143b2b416aacefb555e3045c356faa23e6d21de72b85822e39fdd',
                bbb: 'fb131bc57a477c8c9d068f1ee5622ac304195a77164ccc2d75d82dfe1a727ba8d674ed87f96143b2b416aacefb555e3045c356faa23e6d21de72b85822e39fdd',
              },
            },
          });
        });
      });
    
      describe('ensureCommentRemoval', () => {
        beforeEach(() => {
          platform.ensureCommentRemoval.mockResolvedValueOnce();
          platform.ensureComment.mockResolvedValue(true);
        });
    
        it('deletes cached comment by topic', async () => {
          await ensureComment({ number: 1, topic: 'aaa', content: '111' });
          await ensureCommentRemoval({ type: 'by-topic', number: 1, topic: 'aaa' });
          expect(repoCache).toEqual({
            prComments: { '1': {} },
          });
        });
    
        it('deletes cached comment by content', async () => {
          await ensureComment({ number: 1, topic: 'aaa', content: '111' });
          await ensureCommentRemoval({
            type: 'by-content',
            number: 1,
            content: '111',
          });
          expect(repoCache).toEqual({
            prComments: { '1': {} },
          });
        });
    
        it('deletes by content only one comment', async () => {
          await ensureComment({ number: 1, topic: 'aaa', content: '111' });
          await ensureComment({ number: 1, topic: 'bbb', content: '111' });
          await ensureCommentRemoval({
            type: 'by-content',
            number: 1,
            content: '111',
          });
          expect(repoCache).toEqual({
            prComments: {
              '1': {
                bbb: 'fb131bc57a477c8c9d068f1ee5622ac304195a77164ccc2d75d82dfe1a727ba8d674ed87f96143b2b416aacefb555e3045c356faa23e6d21de72b85822e39fdd',
              },
            },
          });
        });
    
        it('deletes only for selected PR', async () => {
          await ensureComment({ number: 1, topic: 'aaa', content: '111' });
          await ensureComment({ number: 2, topic: 'aaa', content: '111' });
          await ensureCommentRemoval({
            type: 'by-content',
            number: 1,
            content: '111',
          });
          expect(repoCache).toEqual({
            prComments: {
              '1': {},
              '2': {
                aaa: 'fb131bc57a477c8c9d068f1ee5622ac304195a77164ccc2d75d82dfe1a727ba8d674ed87f96143b2b416aacefb555e3045c356faa23e6d21de72b85822e39fdd',
              },
            },
          });
        });
      });
    });