Skip to content

Commit 3ceaf57

Browse files
authored
[#IOPID-369] add constant integer generation (#321)
1 parent eb6e997 commit 3ceaf57

File tree

13 files changed

+212
-731
lines changed

13 files changed

+212
-731
lines changed

Diff for: .devops/code-review-pipelines.yml

+1-24
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
# Azure DevOps pipeline to build, check source codes and run tests.
2-
#
3-
# To make Danger JS run on a pull request you need to add the following pipeline
4-
# variable and set it with a GitHub access token (scope public_repo); otherwise
5-
# set its value to 'skip' without marking it secret:
6-
# - DANGER_GITHUB_API_TOKEN
7-
#
82

93
variables:
104
NODE_VERSION: '12.19.1'
@@ -41,23 +35,6 @@ stages:
4135
yarn e2e:lint
4236
displayName: 'Lint e2e project'
4337
44-
- job: danger
45-
condition:
46-
and(
47-
succeeded(),
48-
and(
49-
eq(variables['Build.Reason'], 'PullRequest'),
50-
ne(variables['DANGER_GITHUB_API_TOKEN'], 'skip')
51-
)
52-
)
53-
steps:
54-
- template: azure-templates/setup-project.yml
55-
- bash: |
56-
yarn danger ci
57-
env:
58-
DANGER_GITHUB_API_TOKEN: '$(DANGER_GITHUB_API_TOKEN)'
59-
displayName: 'Danger CI'
60-
6138
- stage: Test
6239
dependsOn: []
6340
jobs:
@@ -72,7 +49,7 @@ stages:
7249
bash <(curl -s https://codecov.io/bash)
7350
displayName: 'Code coverage'
7451
75-
- stage: Teste_2e
52+
- stage: Test_e2e
7653
dependsOn: []
7754
jobs:
7855
- job: e2e_tests

Diff for: .eslintrc.js

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ module.exports = {
99
"generated",
1010
"**/__tests__/*",
1111
"**/__mocks__/*",
12-
"Dangerfile.*",
1312
"*.d.ts"
1413
],
1514
"parser": "@typescript-eslint/parser",

Diff for: .github/workflows/pr-title-linter-and-linker.yaml

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: "Lint and Link PR title"
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- edited
8+
- reopened
9+
- synchronize
10+
11+
jobs:
12+
lint:
13+
name: Validate PR title And link Jira Issue
14+
runs-on: ubuntu-22.04
15+
env:
16+
JIRA_COMMENT_REGEX: "^.*Jira.*"
17+
steps:
18+
- uses: Slashgear/action-check-pr-title@860e8dc639f8e60335a6f5e8936ba67ed2536890
19+
id: lint
20+
with:
21+
regexp: "\\[(#?[A-Z]*-[0-9]*( |, )?){1,}\\]" # Regex the title should match.
22+
continue-on-error: true
23+
24+
- name: Find Jira Comment
25+
uses: peter-evans/find-comment@81e2da3af01c92f83cb927cf3ace0e085617c556
26+
id: fc
27+
with:
28+
issue-number: ${{ github.event.pull_request.number }}
29+
comment-author: 'github-actions[bot]'
30+
body-regex: "${{ env.JIRA_COMMENT_REGEX }}"
31+
32+
- name: Extract Jira Issue to Link
33+
id: extract_jira_issue
34+
if: steps.lint.outcome == 'success'
35+
run: |
36+
PR_TITLE=$(echo "${{ github.event.pull_request.title }}")
37+
ISSUES_STR=$(awk -F'\\[|\\]' '{print $2}' <<< "$PR_TITLE" | sed "s/#//g" | sed "s/,//g")
38+
ISSUES=($ISSUES_STR)
39+
JIRA_ISSUE=$(echo ${ISSUES_STR##* })
40+
MARKDOWN_CARRIAGE_RETURN="<br>"
41+
MARKDOWN_PREFIX="- Link to"
42+
JIRA_COMMENT_MARKDOWN="This Pull Request refers to Jira issues:<br>"
43+
if [[ ${#ISSUES[@]} -eq 1 ]]
44+
then
45+
JIRA_COMMENT_MARKDOWN="This Pull Request refers to the following Jira issue"
46+
MARKDOWN_PREFIX=""
47+
fi
48+
49+
for ISSUE in "${ISSUES[@]}"
50+
do
51+
JIRA_COMMENT_MARKDOWN+="$MARKDOWN_PREFIX [$ISSUE](https://pagopa.atlassian.net/browse/$ISSUE) $MARKDOWN_CARRIAGE_RETURN"
52+
done
53+
54+
echo "JIRA_ISSUE=$JIRA_ISSUE" >> $GITHUB_ENV
55+
echo "JIRA_COMMENT_MARKDOWN=$JIRA_COMMENT_MARKDOWN" >> $GITHUB_ENV
56+
57+
- name: Create Jira Link comment
58+
if: steps.lint.outcome == 'success'
59+
uses: peter-evans/create-or-update-comment@5adcb0bb0f9fb3f95ef05400558bdb3f329ee808
60+
with:
61+
comment-id: ${{ steps.fc.outputs.comment-id }}
62+
issue-number: ${{ github.event.pull_request.number }}
63+
body: |
64+
## Jira Pull Request Link ##
65+
${{ env.JIRA_COMMENT_MARKDOWN }}
66+
edit-mode: replace
67+
- name: Create Empty Jira Link comment
68+
if: steps.lint.outcome != 'success'
69+
uses: peter-evans/create-or-update-comment@5adcb0bb0f9fb3f95ef05400558bdb3f329ee808
70+
with:
71+
comment-id: ${{ steps.fc.outputs.comment-id }}
72+
issue-number: ${{ github.event.pull_request.number }}
73+
body: |
74+
## Jira Pull request Link ##
75+
It seems this Pull Request has no issues that refers to Jira!!!
76+
Please check it out.
77+
edit-mode: replace
78+
- name: Failure message
79+
if: steps.lint.outcome != 'success'
80+
run: |
81+
echo "Pull request title (${{ github.event.pull_request.title }}) is not properly formatted or it is not related to any Jira issue"
82+
exit 1

Diff for: Dangerfile.ts

-7
This file was deleted.

Diff for: __mocks__/api.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,10 @@ definitions:
382382
AdditionalPropsTrueTest:
383383
type: object
384384
additionalProperties: true
385+
ConstantIntegerTest:
386+
title: ConstantIntegerTest
387+
type: integer
388+
enum: [100]
385389
NonNegativeNumberTest:
386390
title: NonNegativeNumberTest
387391
type: number

Diff for: __mocks__/openapi_v3/api.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,10 @@ components:
580580
title: NonNegativeNumberTest
581581
type: number
582582
minimum: 0
583+
ConstantIntegerTest:
584+
title: ConstantIntegerTest
585+
type: integer
586+
enum: [100]
583587
NonNegativeIntegerTest:
584588
title: NonNegativeIntegerTest
585589
type: integer

Diff for: e2e/src/__tests__/test-api-v3/definitions.test.ts

+28-15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { WithinRangeExclusiveMinimumIntegerTest } from "../../generated/testapiV
1010
import { WithinRangeExclusiveMinimumNumberTest } from "../../generated/testapiV3/WithinRangeExclusiveMinimumNumberTest";
1111
import { WithinRangeExclusiveMinMaxNumberTest } from "../../generated/testapiV3/WithinRangeExclusiveMinMaxNumberTest";
1212

13+
import { ConstantIntegerTest } from "../../generated/testapiV3/ConstantIntegerTest";
14+
1315
import { WithinRangeIntegerTest } from "../../generated/testapiV3/WithinRangeIntegerTest";
1416
import { WithinRangeNumberTest } from "../../generated/testapiV3/WithinRangeNumberTest";
1517
import { WithinRangeStringTest } from "../../generated/testapiV3/WithinRangeStringTest";
@@ -19,8 +21,8 @@ import { DisjointUnionsUserTest } from "../../generated/testapiV3/DisjointUnions
1921
import { EnabledUserTest } from "../../generated/testapiV3/EnabledUserTest";
2022
import { EnumFalseTest } from "../../generated/testapiV3/EnumFalseTest";
2123
import { EnumTrueTest } from "../../generated/testapiV3/EnumTrueTest";
22-
import {AllOfWithOneElementTest} from "../../generated/testapiV3/AllOfWithOneElementTest";
23-
import {AllOfWithOneRefElementTest} from "../../generated/testapiV3/AllOfWithOneRefElementTest";
24+
import { AllOfWithOneElementTest } from "../../generated/testapiV3/AllOfWithOneElementTest";
25+
import { AllOfWithOneRefElementTest } from "../../generated/testapiV3/AllOfWithOneRefElementTest";
2426

2527
import * as E from "fp-ts/lib/Either";
2628

@@ -101,6 +103,19 @@ describe("Profile defintion", () => {
101103
});
102104
});
103105

106+
describe("ConstantIntegerTest definition", () => {
107+
it.each`
108+
value | expected
109+
${100} | ${true}
110+
${99} | ${false}
111+
${101} | ${false}
112+
${199} | ${false}
113+
`("should decode $value with ConstantIntegerTest", ({ value, expected }) => {
114+
const result = ConstantIntegerTest.decode(value);
115+
expect(E.isRight(result)).toEqual(expected);
116+
});
117+
});
118+
104119
describe("WithinRangeIntegerTest definition", () => {
105120
// WithinRangeIntegerTest is defined min=0 max=10 in the spec
106121
it.each`
@@ -325,23 +340,20 @@ describe("EnumFalseTest definition", () => {
325340
});
326341

327342
describe("AllOfWithOneElementTest definition", () => {
328-
329-
const okElement = {key: "string"};
330-
const notOkElement = {key: 1};
343+
const okElement = { key: "string" };
344+
const notOkElement = { key: 1 };
331345

332346
it("Should return a right", () => {
333347
expect(E.isRight(AllOfWithOneElementTest.decode(okElement))).toBeTruthy();
334-
})
348+
});
335349

336350
it("Should return a left", () => {
337351
expect(E.isLeft(AllOfWithOneElementTest.decode(notOkElement))).toBeTruthy();
338-
})
339-
340-
})
352+
});
353+
});
341354

342355
describe("AllOfWithOneRefElementTest", () => {
343-
344-
const basicProfile = {
356+
const basicProfile = {
345357
family_name: "Rossi",
346358
fiscal_code: "RSSMRA80A01F205X",
347359
has_profile: true,
@@ -351,10 +363,11 @@ const basicProfile = {
351363
};
352364

353365
it("Should return a right", () => {
354-
expect(E.isRight(AllOfWithOneRefElementTest.decode(basicProfile))).toBeTruthy();
355-
})
356-
357-
})
366+
expect(
367+
E.isRight(AllOfWithOneRefElementTest.decode(basicProfile))
368+
).toBeTruthy();
369+
});
370+
});
358371

359372
describe("DisjointUnionsUserTest definition", () => {
360373
const enabledUser = {

Diff for: e2e/src/__tests__/test-api/definitions.test.ts

+33-23
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { WithinRangeExclusiveMinimumIntegerTest } from "../../generated/testapi/
1010
import { WithinRangeExclusiveMinimumNumberTest } from "../../generated/testapi/WithinRangeExclusiveMinimumNumberTest";
1111
import { WithinRangeExclusiveMinMaxNumberTest } from "../../generated/testapi/WithinRangeExclusiveMinMaxNumberTest";
1212

13+
import { ConstantIntegerTest } from "../../generated/testapi/ConstantIntegerTest";
14+
1315
import { WithinRangeIntegerTest } from "../../generated/testapi/WithinRangeIntegerTest";
1416
import { WithinRangeNumberTest } from "../../generated/testapi/WithinRangeNumberTest";
1517
import { WithinRangeStringTest } from "../../generated/testapi/WithinRangeStringTest";
@@ -23,8 +25,7 @@ import { AllOfWithOneElementTest } from "../../generated/testapi/AllOfWithOneEle
2325
import { AllOfWithOneRefElementTest } from "../../generated/testapi/AllOfWithOneRefElementTest";
2426
import { AdditionalPropsTest } from "../../generated/testapi/AdditionalPropsTest";
2527

26-
27-
import * as E from "fp-ts/lib/Either"
28+
import * as E from "fp-ts/lib/Either";
2829

2930
const { generatedFilesDir } = config.specs.testapi;
3031

@@ -103,6 +104,19 @@ describe("Profile defintion", () => {
103104
});
104105
});
105106

107+
describe("ConstantIntegerTest definition", () => {
108+
it.each`
109+
value | expected
110+
${100} | ${true}
111+
${99} | ${false}
112+
${101} | ${false}
113+
${199} | ${false}
114+
`("should decode $value with ConstantIntegerTest", ({ value, expected }) => {
115+
const result = ConstantIntegerTest.decode(value);
116+
expect(E.isRight(result)).toEqual(expected);
117+
});
118+
});
119+
106120
describe("WithinRangeIntegerTest defintion", () => {
107121
// WithinRangeIntegerTest is defined min=0 max=10 in the spec
108122
it.each`
@@ -327,42 +341,37 @@ describe("EnumFalseTest definition", () => {
327341
});
328342

329343
describe("AllOfWithOneElementTest definition", () => {
330-
331-
const okElement = {key: "string"};
332-
const notOkElement = {key: 1};
344+
const okElement = { key: "string" };
345+
const notOkElement = { key: 1 };
333346

334347
it("Should return a right", () => {
335348
expect(E.isRight(AllOfWithOneElementTest.decode(okElement))).toBeTruthy();
336-
})
349+
});
337350

338351
it("Should return a left", () => {
339352
expect(E.isLeft(AllOfWithOneElementTest.decode(notOkElement))).toBeTruthy();
340-
})
341-
342-
})
353+
});
354+
});
343355

344356
describe("AdditionalPropsTest should be an object with a string as key and an array of number as value", () => {
345-
346-
const okElement = {"okElementProperty": [1, 2, 3]};
347-
const notOkElement = {"notOkElementProperty": ["1", "2", "3"]};
357+
const okElement = { okElementProperty: [1, 2, 3] };
358+
const notOkElement = { notOkElementProperty: ["1", "2", "3"] };
348359

349360
it("Should return a right with a valid type", () => {
350361
expect(E.isRight(AdditionalPropsTest.decode(okElement))).toBeTruthy();
351-
})
362+
});
352363

353364
it("Should return a left with a non valid element", () => {
354365
expect(E.isLeft(AdditionalPropsTest.decode(notOkElement))).toBeTruthy();
355-
})
366+
});
356367

357368
it("Should return a left with undefined input", () => {
358369
expect(E.isLeft(AdditionalPropsTest.decode(undefined))).toBeTruthy();
359-
})
360-
361-
})
370+
});
371+
});
362372

363373
describe("AllOfWithOneRefElementTest", () => {
364-
365-
const basicProfile = {
374+
const basicProfile = {
366375
family_name: "Rossi",
367376
fiscal_code: "RSSMRA80A01F205X",
368377
has_profile: true,
@@ -372,10 +381,11 @@ const basicProfile = {
372381
};
373382

374383
it("Should return a right", () => {
375-
expect(E.isRight(AllOfWithOneRefElementTest.decode(basicProfile))).toBeTruthy();
376-
})
377-
378-
})
384+
expect(
385+
E.isRight(AllOfWithOneRefElementTest.decode(basicProfile))
386+
).toBeTruthy();
387+
});
388+
});
379389

380390
describe("DisjointUnionsUserTest definition", () => {
381391
const enabledUser = {

Diff for: package.json

-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848
"@types/yargs": "^11.1.0",
4949
"auto-changelog": "^2.2.1",
5050
"crlf": "^1.1.1",
51-
"danger": "^3.5.1",
52-
"danger-plugin-digitalcitizenship": "^0.3.1",
5351
"eslint-plugin-prettier": "^3.3.1",
5452
"jest": "^25.2.7",
5553
"rimraf": "^2.6.2",

0 commit comments

Comments
 (0)