Skip to content

Commit

Permalink
Mappings with versions are working now!
Browse files Browse the repository at this point in the history
- Org rule files are broken still
- Documentation still needs to be updated
  • Loading branch information
manchicken committed Jun 23, 2023
1 parent e0643a3 commit bf9c994
Show file tree
Hide file tree
Showing 10 changed files with 887 additions and 591 deletions.
87 changes: 87 additions & 0 deletions __tests__/lib/__snapshots__/fieldMappings-schema.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`constants convenienceFields 1`] = `
[
"email",
"slack",
"repo",
"opsgenie",
"pagerduty",
"slack-support-channel",
]
`;

exports[`constants mappings 1`] = `
{
"application": {
"v2": [Function],
"v2.1": [Function],
},
"contacts": {
"v2": [Function],
"v2.1": [Function],
},
"description": {
"v2": [Function],
"v2.1": [Function],
},
"docs": {
"v2": [Function],
"v2.1": [Function],
},
"integrations": {
"v2": [Function],
"v2.1": [Function],
},
"lifecycle": {
"v2": [Function],
"v2.1": [Function],
},
"links": {
"v2": [Function],
"v2.1": [Function],
},
"repos": {
"v2": [Function],
"v2.1": [Function],
},
"schema-version": {
"v2": [Function],
"v2.1": [Function],
},
"service-name": {
"v2": [Function],
"v2.1": [Function],
},
"tags": {
"v2": [Function],
"v2.1": [Function],
},
"team": {
"v2": [Function],
"v2.1": [Function],
},
"tier": {
"v2": [Function],
"v2.1": [Function],
},
}
`;

exports[`constants schemaFields 1`] = `
[
"schema-version",
"service-name",
"team",
"contacts",
"tags",
"links",
"integrations",
"docs",
"repos",
"application",
"description",
"tier",
"lifecycle",
]
`;
60 changes: 18 additions & 42 deletions __tests__/lib/__snapshots__/fieldMappings.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

exports[`constants convenienceFields 1`] = `
[
"email",
"slack",
"repo",
"opsgenie",
"pagerduty",
"email",
"slack-support-channel",
"repo",
]
`;

Expand All @@ -28,10 +29,6 @@ exports[`constants mappings 1`] = `
"v2": [Function],
"v2.1": [Function],
},
"email": {
"v2": [Function],
"v2.1": [Function],
},
"integrations": {
"v2": [Function],
"v2.1": [Function],
Expand All @@ -44,18 +41,6 @@ exports[`constants mappings 1`] = `
"v2": [Function],
"v2.1": [Function],
},
"opsgenie": {
"v2": [Function],
"v2.1": [Function],
},
"pagerduty": {
"v2": [Function],
"v2.1": [Function],
},
"repo": {
"v2": [Function],
"v2.1": [Function],
},
"repos": {
"v2": [Function],
"v2.1": [Function],
Expand All @@ -68,10 +53,6 @@ exports[`constants mappings 1`] = `
"v2": [Function],
"v2.1": [Function],
},
"slack-support-channel": {
"v2": [Function],
"v2.1": [Function],
},
"tags": {
"v2": [Function],
"v2.1": [Function],
Expand All @@ -88,24 +69,19 @@ exports[`constants mappings 1`] = `
`;

exports[`constants schemaFields 1`] = `
{
"0": "schema-version",
"1": "service-name",
"10": "description",
"11": "tier",
"12": "lifecycle",
"13": "email",
"14": "slack-support-channel",
"15": "repo",
"16": "opsgenie",
"17": "pagerduty",
"2": "team",
"3": "contacts",
"4": "tags",
"5": "links",
"6": "integrations",
"7": "docs",
"8": "repos",
"9": "application",
}
[
"schema-version",
"service-name",
"team",
"contacts",
"tags",
"links",
"integrations",
"docs",
"repos",
"application",
"description",
"tier",
"lifecycle",
]
`;
209 changes: 209 additions & 0 deletions __tests__/lib/fieldMappings-convenience.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
/**
* @fileoverview This test covers all of the field mappings across versions.
**/

const core = require('@actions/core')
const {
mappings,
convenienceFields,
schemaFields,
mapField,
} = require('../../lib/fieldMappings')

describe.each([
{
version: 'v2',
field: 'email',
input: 'testing@manchicken.io',
doc: {},
value: {
contacts: [{ type: 'email', contact: 'testing@manchicken.io' }],
},
},
{
version: 'v2',
field: 'email',
input: 'testing@manchicken.io',
doc: {
contacts: [
{
name: 'test',
type: 'slack',
contact: 'https://my-org.slack.com/archives/my-channel',
},
],
},
value: {
contacts: [
{
name: 'test',
type: 'slack',
contact: 'https://my-org.slack.com/archives/my-channel',
},
{ type: 'email', contact: 'testing@manchicken.io' },
],
},
},
{
version: 'v2.1',
field: 'email',
input: 'testing@manchicken.io',
doc: {
contacts: [
{
name: 'test',
type: 'slack',
contact: 'https://my-org.slack.com/archives/my-channel',
},
],
},
value: {
contacts: [
{
name: 'test',
type: 'slack',
contact: 'https://my-org.slack.com/archives/my-channel',
},
{ type: 'email', contact: 'testing@manchicken.io' },
],
},
},
{
version: 'v2',
field: 'slack',
input: 'https://my-org.slack.com/archives/my-channel',
doc: {},
value: {
contacts: [
{
type: 'slack',
contact: 'https://my-org.slack.com/archives/my-channel',
},
],
},
},
{
version: 'v2',
field: 'slack',
input: 'https://my-org.slack.com/archives/my-channel',
doc: {
contacts: [{ type: 'email', contact: 'testing@manchicken.io' }],
},
value: {
contacts: [
{ type: 'email', contact: 'testing@manchicken.io' },
{
type: 'slack',
contact: 'https://my-org.slack.com/archives/my-channel',
},
],
},
},
{
version: 'v2.1',
field: 'slack',
input: 'https://my-org.slack.com/archives/my-channel',
doc: {
contacts: [{ type: 'email', contact: 'testing@manchicken.io' }],
},
value: {
contacts: [
{ type: 'email', contact: 'testing@manchicken.io' },
{
type: 'slack',
contact: 'https://my-org.slack.com/archives/my-channel',
},
],
},
},
{
version: 'v2',
field: 'opsgenie',
input:
'https://www.opsgenies.com/service/123e4567-e89b-12d3-a456-426614174000',
doc: {
contacts: [{ type: 'email', contact: 'testing@manchicken.io' }],
},
value: {
contacts: [{ type: 'email', contact: 'testing@manchicken.io' }],
integrations: {
opsgenie: {
'service-url':
'https://www.opsgenies.com/service/123e4567-e89b-12d3-a456-426614174000',
},
},
},
},
{
version: 'v2.1',
field: 'opsgenie',
input:
'https://www.opsgenies.com/service/123e4567-e89b-12d3-a456-426614174000',
doc: {
contacts: [{ type: 'email', contact: 'testing@manchicken.io' }],
},
value: {
contacts: [{ type: 'email', contact: 'testing@manchicken.io' }],
integrations: {
opsgenie: {
'service-url':
'https://www.opsgenies.com/service/123e4567-e89b-12d3-a456-426614174000',
},
},
},
},
{
version: 'v2',
field: 'pagerduty',
input: 'https://my-org.pagerduty.com/service-directory/PMyService',
doc: {
integrations: {
opsgenie: {
'service-url':
'https://www.opsgenies.com/service/123e4567-e89b-12d3-a456-426614174000',
},
},
},
value: {
integrations: {
opsgenie: {
'service-url':
'https://www.opsgenies.com/service/123e4567-e89b-12d3-a456-426614174000',
},
pagerduty: 'https://my-org.pagerduty.com/service-directory/PMyService',
},
},
},
{
version: 'v2.1',
field: 'pagerduty',
input: 'https://my-org.pagerduty.com/service-directory/PMyService',
doc: {
integrations: {
opsgenie: {
'service-url':
'https://www.opsgenies.com/service/123e4567-e89b-12d3-a456-426614174000',
},
},
},
value: {
integrations: {
opsgenie: {
'service-url':
'https://www.opsgenies.com/service/123e4567-e89b-12d3-a456-426614174000',
},
pagerduty: {
'service-url':
'https://my-org.pagerduty.com/service-directory/PMyService',
},
},
},
},
])('$field:$version', ({ version, field, input, doc, value }) => {
beforeEach(() => {
core.setFailed.mockClear()
})
test('mapping', () => {
expect(mapField(field, version)(input, doc)).toEqual(value)
})
})
Loading

0 comments on commit bf9c994

Please sign in to comment.