Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add valid schemas #797

Merged
merged 4 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions .github/workflows/cypress_unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,10 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: run server with the front of the game
run: python3 -m http.server 8080 &

- name: check whether game is UP
run: |
curl -X GET "http://localhost:8080/"


- name: cypress run
uses: cypress-io/github-action@v5
with:
working-directory: tests/tests_cypress/unit
run: npm install chai-json-schema
start: npm run start
7,626 changes: 7,625 additions & 1 deletion .gitignore

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions js/objects_artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var artefacts = {
},
artid01: {
id: "artid01",
img: "medal.png",
name: {
"default":"Four-Leaf Clover",
"en-US":"Four-Leaf Clover",
Expand All @@ -48,6 +49,7 @@ var artefacts = {
},
artid02: {
id: "artid02",
img: "medal.png",
name: {
"default": "Medal of Valor",
"en-US": "Medal of Valor",
Expand All @@ -68,6 +70,7 @@ var artefacts = {
},
artid03: {
id: "artid03",
img: "medal.png",
name: {
"default": "Medal of Courage",
"en-US": "Medal of Courage",
Expand All @@ -88,6 +91,7 @@ var artefacts = {
},
artid04: {
id: "artid04",
img: "medal.png",
name: {
"default": "Medal of Honor",
"en-US": "Medal of Honor",
Expand All @@ -108,6 +112,7 @@ var artefacts = {
},
artid05: {
id: "artid05",
img: "medal.png",
name: {
"default": "Medal of Distinction",
"en-US": "Medal of Distinction",
Expand All @@ -128,6 +133,7 @@ var artefacts = {
},
artid06: {
id: "artid06",
img: "medal.png",
name: {
"default": "Rabbit's Foot",
"en-US": "Rabbit's Foot",
Expand All @@ -148,6 +154,7 @@ var artefacts = {
},
artid07: {
id: "artid07",
img: "medal.png",
name: {
"default": "Golden Horseshoe",
"en-US": "Golden Horseshoe",
Expand All @@ -168,6 +175,7 @@ var artefacts = {
},
artid08: {
id: "artid08",
img: "medal.png",
name: {
"default": "Gambler's Lucky Coin",
"en-US": "Gambler's Lucky Coin",
Expand All @@ -188,6 +196,7 @@ var artefacts = {
},
artid09: {
id: "artid09",
img: "sand_clock.png",
name: {
"default": "Unlucky hourglass",
"en-US": "Unlucky hourglass",
Expand All @@ -208,6 +217,7 @@ var artefacts = {
},
artid10: {
id: "artid10",
img: "medal.png",
name: {
"default": "Glass globe",
"en-US": "Glass globe",
Expand Down
Binary file added resources/medal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/tests_cypress/unit/cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

export default ({
e2e: {
baseUrl: 'http://localhost:8080',

setupNodeEvents(on, config) {
video: false;
// implement node event listeners here
Expand Down
134 changes: 58 additions & 76 deletions tests/tests_cypress/unit/cypress/e2e/check_object_property.cy.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,47 @@
import artefacts from '../../../../../js/objects_artifacts'
import tech_list from '../../../../../js/objects_technology_tree'

describe('Сhecking object properties in file: ', () => {

beforeEach(() => {
cy.visit('/')

Cypress.on('uncaught:exception', (err, runnable) => {
return false;
});

//close windows canvas
cy.window().then((win) => {
win.eval('document.getElementById("myDCanvas").classList.remove("active-modal")');
});

})


it('Сhecking object properties file objects_technology_tree.js', () => {

// *********************************************************************
// Checking the file objects_technology_tree.js
// *********************************************************************

let techList;
let techKey;
let checkTech;
let tempCheckTech;

cy.window().then((win) => {
techList = win.eval('Object.keys(tech_list)');

techList.forEach(function (item) {
checkTech = win.eval('tech_list.' + item);

techList.forEach(function (tempItem) {
tempCheckTech = win.eval('tech_list.' + tempItem);

if (checkTech === tempCheckTech) {
expect(tempCheckTech.id).to.eql(checkTech.id);
expect(tempCheckTech.name['default'], tempItem).to.eql(checkTech.name['default']);
expect(tempCheckTech.name['en-US'], tempItem).to.eql(checkTech.name['en-US']);
expect(tempCheckTech.name['ru-RU'], tempItem).to.eql(checkTech.name['ru-RU']);
} else {
if (tempCheckTech.id === checkTech.id) {
expect(tempCheckTech.id, tempItem + " duplicates the property of the " + item).to.not.eql(checkTech.id)
}
if (tempCheckTech.name['default'] === checkTech.name['default'] ||
tempCheckTech.name['en-US'] === checkTech.name['en-US'] ||
tempCheckTech.name['ru-RU'] === checkTech.name['ru-RU']
) {
expect(tempCheckTech.name['default'], tempItem + " duplicates the property of the " + item).to.not.eql(checkTech.name['default']);
expect(tempCheckTech.name['en-US'], tempItem + " duplicates the property of the " + item).to.not.eql(checkTech.name['en-US']);
expect(tempCheckTech.name['ru-RU'], tempItem + " duplicates the property of the " + item).to.not.eql(checkTech.name['ru-RU']);
}
}
})
techKey = Object.keys(tech_list);

techKey.forEach(function (item) {
checkTech = tech_list[item];

techKey.forEach(function (tempItem) {
tempCheckTech = tech_list[tempItem];

if (checkTech === tempCheckTech) {
expect(tempCheckTech.id).to.eql(checkTech.id);
expect(tempCheckTech.name['default'], tempItem).to.eql(checkTech.name['default']);
expect(tempCheckTech.name['en-US'], tempItem).to.eql(checkTech.name['en-US']);
expect(tempCheckTech.name['ru-RU'], tempItem).to.eql(checkTech.name['ru-RU']);
} else {
if (tempCheckTech.id === checkTech.id) {
expect(tempCheckTech.id, tempItem + " duplicates the property of the " + item).to.not.eql(checkTech.id)
}
if (tempCheckTech.name['default'] === checkTech.name['default'] ||
tempCheckTech.name['en-US'] === checkTech.name['en-US'] ||
tempCheckTech.name['ru-RU'] === checkTech.name['ru-RU']
) {
expect(tempCheckTech.name['default'], tempItem + " duplicates the property of the " + item).to.not.eql(checkTech.name['default']);
expect(tempCheckTech.name['en-US'], tempItem + " duplicates the property of the " + item).to.not.eql(checkTech.name['en-US']);
expect(tempCheckTech.name['ru-RU'], tempItem + " duplicates the property of the " + item).to.not.eql(checkTech.name['ru-RU']);
}
}
})

});
})
});

it('Сhecking object properties file objects_artifacts.js', () => {
Expand All @@ -65,42 +50,39 @@ describe('Сhecking object properties in file: ', () => {
// Checking the file objects_artifacts.js
// *********************************************************************

let artefacts;
let artefactsKey;
let checkArt;
let tempCheckArt;

cy.window().then((win) => {
artefacts = win.eval('Object.keys(artefacts)');

console.log(artefacts);
artefacts.forEach(function (item) {
checkArt = win.eval('artefacts.' + item);

artefacts.forEach(function (tempItem) {
tempCheckArt = win.eval('artefacts.' + tempItem);

if (checkArt === tempCheckArt) {
expect(tempCheckArt.id).to.eql(checkArt.id);
expect(tempCheckArt.name['default']).to.eql(checkArt.name['default']);
expect(tempCheckArt.name['en-US']).to.eql(checkArt.name['en-US']);
expect(tempCheckArt.name['ru-RU']).to.eql(checkArt.name['ru-RU']);
} else {
if (tempCheckArt.id === checkArt.id) {
expect(tempCheckArt.id, tempItem + " duplicates the property of the " + item).to.not.eql(checkArt.id)
}
if (tempCheckArt.name['default'] === checkArt.name['default'] ||
tempCheckArt.name['en-US'] === checkArt.name['en-US'] ||
tempCheckArt.name['ru-RU'] === checkArt.name['ru-RU']
) {
expect(tempCheckArt.name['default'], tempItem + " duplicates the property of the " + item).to.not.eql(checkArt.name['default']);
expect(tempCheckArt.name['en-US'], tempItem + " duplicates the property of the " + item).to.not.eql(checkArt.name['en-US']);
expect(tempCheckArt.name['ru-RU'], tempItem + " duplicates the property of the " + item).to.not.eql(checkArt.name['ru-RU']);
}
}
})
artefactsKey = Object.keys(artefacts);

artefactsKey.forEach(function (item) {
checkArt = artefacts[item];

artefactsKey.forEach(function (tempItem) {
tempCheckArt = artefacts[tempItem];

if (checkArt === tempCheckArt) {
expect(tempCheckArt.id).to.eql(checkArt.id);
expect(tempCheckArt.name['default']).to.eql(checkArt.name['default']);
expect(tempCheckArt.name['en-US']).to.eql(checkArt.name['en-US']);
expect(tempCheckArt.name['ru-RU']).to.eql(checkArt.name['ru-RU']);
} else {
if (tempCheckArt.id === checkArt.id) {
expect(tempCheckArt.id, tempItem + " duplicates the property of the " + item).to.not.eql(checkArt.id)
}
if (tempCheckArt.name['default'] === checkArt.name['default'] ||
tempCheckArt.name['en-US'] === checkArt.name['en-US'] ||
tempCheckArt.name['ru-RU'] === checkArt.name['ru-RU']
) {
expect(tempCheckArt.name['default'], tempItem + " duplicates the property of the " + item).to.not.eql(checkArt.name['default']);
expect(tempCheckArt.name['en-US'], tempItem + " duplicates the property of the " + item).to.not.eql(checkArt.name['en-US']);
expect(tempCheckArt.name['ru-RU'], tempItem + " duplicates the property of the " + item).to.not.eql(checkArt.name['ru-RU']);
}
}
})

});
})

});
});
50 changes: 50 additions & 0 deletions tests/tests_cypress/unit/cypress/e2e/check_schema_json.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { artSchema } from '../schemas/artifacts_schema'
import { technologySchema } from '../schemas/technology_tree_schema'
import artefacts from '../../../../../js/objects_artifacts'
import tech_list from '../../../../../js/objects_technology_tree'


describe('Сhecking object properties in file: ', () => {

it('Valid JSON object artifact ', () => {

// *********************************************************************
// Checking the schema file objects_artifacts.js
// *********************************************************************

let artefactsKey;
artefactsKey = Object.keys(artefacts);
artefactsKey.forEach(function (item) {
expect(artefacts[item], item).to.be.jsonSchema(artSchema);
});
})

it('Сhecking for the presence of property "artefactsWorn" for object artid', () => {

let artefactsKey;

artefactsKey = Object.keys(artefacts);
artefactsKey.forEach(function (item) {
if (artefacts[item].type == 'artefactsWorn') {
expect(artefacts[item], item + ' have the property "artefactsWorn"').to.property('artefactsWorn')
}
else {
expect(artefacts[item], item + ' does not have the property "artefactsWorn"').to.not.property('artefactsWorn');
}
});
})

it('Valid JSON object technology tree', () => {

// *********************************************************************
// Checking the schema file objects_technology_tree.js
// *********************************************************************

let techKey;
const technologyO = tech_list;
techKey = Object.keys(technologyO);
techKey.forEach(function (item) {
expect(technologyO[item], item).to.be.jsonSchema(technologySchema);
});
})
})
Loading