|
1 |
| -import { processBatchedBulkUpdateResp, processWorkflowSubmitResp } from "./jira-client-audit-log-helper"; |
| 1 | +import { processBatchedBulkUpdateResp, processWorkflowSubmitResp, processDeploySubmitResp } from "./jira-client-audit-log-helper"; |
2 | 2 | import { getLogger } from "config/logger";
|
3 | 3 | import { JiraSubmitOptions } from "interfaces/jira";
|
4 | 4 |
|
@@ -647,3 +647,286 @@ describe("processWorkflowSubmitResp", () => {
|
647 | 647 | });
|
648 | 648 | });
|
649 | 649 | });
|
| 650 | + |
| 651 | +describe("processDeploySubmitResp", () => { |
| 652 | + const mockLogger = getLogger("mock-logger"); |
| 653 | + it("should return isSuccess as false when status code is anything other than 202", () => { |
| 654 | + const reqDeploymentDataArray = [ |
| 655 | + { |
| 656 | + schemaVersion: "1.0", |
| 657 | + deploymentSequenceNumber: 1194529862, |
| 658 | + updateSequenceNumber: 2835516764, |
| 659 | + displayName: "Update manifest.json KAM-6", |
| 660 | + url: "https://github.com/KamaksheeSamant/react-cods-hub/actions/runs/7014571070/job/19082502671", |
| 661 | + description: "deploy", |
| 662 | + lastUpdated: "2023-11-28T05:22:38.000Z", |
| 663 | + state: "successful", |
| 664 | + pipeline: { |
| 665 | + id: "deploy", |
| 666 | + displayName: "deploy", |
| 667 | + url: "https://github.com/KamaksheeSamant/react-cods-hub/actions/runs/7014571070/job/19082502671" |
| 668 | + }, |
| 669 | + environment: { |
| 670 | + id: "github-pages", |
| 671 | + displayName: "github-pages", |
| 672 | + type: "unmapped" |
| 673 | + }, |
| 674 | + associations: [ |
| 675 | + { associationType: "issueIdOrKeys", values: ["KAM-6"] }, |
| 676 | + { |
| 677 | + associationType: "commit", |
| 678 | + values: [ |
| 679 | + { |
| 680 | + commitHash: "f4bc81f3ddb980ac34e4ae9acef108e34840567f", |
| 681 | + repositoryId: "691330555" |
| 682 | + } |
| 683 | + ] |
| 684 | + } |
| 685 | + ] |
| 686 | + } |
| 687 | + ]; |
| 688 | + const response = { |
| 689 | + status: 400, |
| 690 | + data: { |
| 691 | + unknownIssueKeys: [], |
| 692 | + acceptedDeployments: [], |
| 693 | + rejectedDeployments: [] |
| 694 | + } |
| 695 | + }; |
| 696 | + const options: JiraSubmitOptions = { preventTransitions:false, operationType: "NORMAL", auditLogsource: "WEBHOOK", subscriptionId: 1122334455 }; |
| 697 | + |
| 698 | + const result = processDeploySubmitResp({ |
| 699 | + reqDeploymentDataArray, |
| 700 | + response, |
| 701 | + options, |
| 702 | + logger: mockLogger |
| 703 | + }); |
| 704 | + |
| 705 | + expect(result).toEqual({ |
| 706 | + isSuccess: false |
| 707 | + }); |
| 708 | + }); |
| 709 | + it("should return isSuccess as false when status code is 202 but there is no acceptedDeployments", () => { |
| 710 | + const reqDeploymentDataArray = [ |
| 711 | + { |
| 712 | + schemaVersion: "1.0", |
| 713 | + deploymentSequenceNumber: 1194529862, |
| 714 | + updateSequenceNumber: 2835516764, |
| 715 | + displayName: "Update manifest.json KAM-6", |
| 716 | + url: "https://github.com/KamaksheeSamant/react-cods-hub/actions/runs/7014571070/job/19082502671", |
| 717 | + description: "deploy", |
| 718 | + lastUpdated: "2023-11-28T05:22:38.000Z", |
| 719 | + state: "successful", |
| 720 | + pipeline: { |
| 721 | + id: "deploy", |
| 722 | + displayName: "deploy", |
| 723 | + url: "https://github.com/KamaksheeSamant/react-cods-hub/actions/runs/7014571070/job/19082502671" |
| 724 | + }, |
| 725 | + environment: { |
| 726 | + id: "github-pages", |
| 727 | + displayName: "github-pages", |
| 728 | + type: "unmapped" |
| 729 | + }, |
| 730 | + associations: [ |
| 731 | + { associationType: "issueIdOrKeys", values: ["KAM-6"] }, |
| 732 | + { |
| 733 | + associationType: "commit", |
| 734 | + values: [ |
| 735 | + { |
| 736 | + commitHash: "f4bc81f3ddb980ac34e4ae9acef108e34840567f", |
| 737 | + repositoryId: "691330555" |
| 738 | + } |
| 739 | + ] |
| 740 | + } |
| 741 | + ] |
| 742 | + } |
| 743 | + ]; |
| 744 | + const response = { |
| 745 | + status: 202, |
| 746 | + data: { |
| 747 | + unknownIssueKeys: [], |
| 748 | + acceptedDeployments: [], |
| 749 | + rejectedDeployments: [] |
| 750 | + } |
| 751 | + }; |
| 752 | + const options: JiraSubmitOptions = { preventTransitions:false, operationType: "NORMAL", auditLogsource: "WEBHOOK", subscriptionId: 1122334455 }; |
| 753 | + |
| 754 | + const result = processDeploySubmitResp({ |
| 755 | + reqDeploymentDataArray, |
| 756 | + response, |
| 757 | + options, |
| 758 | + logger: mockLogger |
| 759 | + }); |
| 760 | + |
| 761 | + expect(result).toEqual({ |
| 762 | + isSuccess: false |
| 763 | + }); |
| 764 | + }); |
| 765 | + it("should return isSuccess as true when status code is 202 and there are/is acceptedDeployments but the result has rejectedDeployments as well", () => { |
| 766 | + const reqDeploymentDataArray = [ |
| 767 | + { |
| 768 | + schemaVersion: "1.0", |
| 769 | + deploymentSequenceNumber: 1194529862, |
| 770 | + updateSequenceNumber: 2835516764, |
| 771 | + displayName: "Update manifest.json KAM-6", |
| 772 | + url: "https://github.com/KamaksheeSamant/react-cods-hub/actions/runs/7014571070/job/19082502671", |
| 773 | + description: "deploy", |
| 774 | + lastUpdated: "2023-11-28T05:22:38.000Z", |
| 775 | + state: "successful", |
| 776 | + pipeline: { |
| 777 | + id: "deploy", |
| 778 | + displayName: "deploy", |
| 779 | + url: "https://github.com/KamaksheeSamant/react-cods-hub/actions/runs/7014571070/job/19082502671" |
| 780 | + }, |
| 781 | + environment: { |
| 782 | + id: "github-pages", |
| 783 | + displayName: "github-pages", |
| 784 | + type: "unmapped" |
| 785 | + }, |
| 786 | + associations: [ |
| 787 | + { associationType: "issueIdOrKeys", values: ["KAM-6"] }, |
| 788 | + { |
| 789 | + associationType: "commit", |
| 790 | + values: [ |
| 791 | + { |
| 792 | + commitHash: "f4bc81f3ddb980ac34e4ae9acef108e34840567f", |
| 793 | + repositoryId: "691330555" |
| 794 | + } |
| 795 | + ] |
| 796 | + } |
| 797 | + ] |
| 798 | + } |
| 799 | + ]; |
| 800 | + const response = { |
| 801 | + status: 202, |
| 802 | + data: { |
| 803 | + unknownIssueKeys: [], |
| 804 | + acceptedDeployments: [ |
| 805 | + { |
| 806 | + pipelineId: "deploy", |
| 807 | + environmentId: "github-pages", |
| 808 | + deploymentSequenceNumber: 1194529862 |
| 809 | + } |
| 810 | + ], |
| 811 | + rejectedDeployments: [ |
| 812 | + { |
| 813 | + pipelineId: "deploy", |
| 814 | + environmentId: "github-pages", |
| 815 | + deploymentSequenceNumber: 1188282781 |
| 816 | + } |
| 817 | + ] |
| 818 | + } |
| 819 | + }; |
| 820 | + const options: JiraSubmitOptions = { preventTransitions:false, operationType: "NORMAL", auditLogsource: "WEBHOOK", subscriptionId: 1122334455 }; |
| 821 | + |
| 822 | + const result = processDeploySubmitResp({ |
| 823 | + reqDeploymentDataArray, |
| 824 | + response, |
| 825 | + options, |
| 826 | + logger: mockLogger |
| 827 | + }); |
| 828 | + |
| 829 | + expect(result).toEqual({ |
| 830 | + isSuccess: true, |
| 831 | + auditInfo: [ |
| 832 | + { |
| 833 | + createdAt: expect.anything(), |
| 834 | + entityAction: "successful", |
| 835 | + entityId: "1194529862", |
| 836 | + entityType: "deployments", |
| 837 | + issueKey: "KAM-6", |
| 838 | + source: "WEBHOOK", |
| 839 | + subscriptionId: 1122334455 |
| 840 | + } |
| 841 | + ] |
| 842 | + }); |
| 843 | + }); |
| 844 | + it("should extract the build with 2 issue keys linked - audit info for logging", () => { |
| 845 | + const reqDeploymentDataArray = [ |
| 846 | + { |
| 847 | + schemaVersion: "1.0", |
| 848 | + deploymentSequenceNumber: 1194529862, |
| 849 | + updateSequenceNumber: 2835516764, |
| 850 | + displayName: "Update manifest.json KAM-6", |
| 851 | + url: "https://github.com/KamaksheeSamant/react-cods-hub/actions/runs/7014571070/job/19082502671", |
| 852 | + description: "deploy", |
| 853 | + lastUpdated: "2023-11-28T05:22:38.000Z", |
| 854 | + state: "successful", |
| 855 | + pipeline: { |
| 856 | + id: "deploy", |
| 857 | + displayName: "deploy", |
| 858 | + url: "https://github.com/KamaksheeSamant/react-cods-hub/actions/runs/7014571070/job/19082502671" |
| 859 | + }, |
| 860 | + environment: { |
| 861 | + id: "github-pages", |
| 862 | + displayName: "github-pages", |
| 863 | + type: "unmapped" |
| 864 | + }, |
| 865 | + associations: [ |
| 866 | + { associationType: "issueIdOrKeys", values: ["KAM-6", "KAM-5"] }, |
| 867 | + { |
| 868 | + associationType: "commit", |
| 869 | + values: [ |
| 870 | + { |
| 871 | + commitHash: "f4bc81f3ddb980ac34e4ae9acef108e34840567f", |
| 872 | + repositoryId: "691330555" |
| 873 | + } |
| 874 | + ] |
| 875 | + } |
| 876 | + ] |
| 877 | + } |
| 878 | + ]; |
| 879 | + const response = { |
| 880 | + status: 202, |
| 881 | + data: { |
| 882 | + unknownIssueKeys: [], |
| 883 | + acceptedDeployments: [ |
| 884 | + { |
| 885 | + pipelineId: "deploy", |
| 886 | + environmentId: "github-pages", |
| 887 | + deploymentSequenceNumber: 1194529862 |
| 888 | + } |
| 889 | + ], |
| 890 | + rejectedDeployments: [ |
| 891 | + { |
| 892 | + pipelineId: "deploy", |
| 893 | + environmentId: "github-pages", |
| 894 | + deploymentSequenceNumber: 1188282781 |
| 895 | + } |
| 896 | + ] |
| 897 | + } |
| 898 | + }; |
| 899 | + const options: JiraSubmitOptions = { preventTransitions:false, operationType: "NORMAL", auditLogsource: "WEBHOOK", subscriptionId: 1122334455 }; |
| 900 | + |
| 901 | + const result = processDeploySubmitResp({ |
| 902 | + reqDeploymentDataArray, |
| 903 | + response, |
| 904 | + options, |
| 905 | + logger: mockLogger |
| 906 | + }); |
| 907 | + |
| 908 | + expect(result).toEqual({ |
| 909 | + isSuccess: true, |
| 910 | + auditInfo: [ |
| 911 | + { |
| 912 | + createdAt: expect.anything(), |
| 913 | + entityAction: "successful", |
| 914 | + entityId: "1194529862", |
| 915 | + entityType: "deployments", |
| 916 | + issueKey: "KAM-6", |
| 917 | + source: "WEBHOOK", |
| 918 | + subscriptionId: 1122334455 |
| 919 | + }, |
| 920 | + { |
| 921 | + createdAt: expect.anything(), |
| 922 | + entityAction: "successful", |
| 923 | + entityId: "1194529862", |
| 924 | + entityType: "deployments", |
| 925 | + issueKey: "KAM-5", |
| 926 | + source: "WEBHOOK", |
| 927 | + subscriptionId: 1122334455 |
| 928 | + } |
| 929 | + ] |
| 930 | + }); |
| 931 | + }); |
| 932 | +}); |
0 commit comments