Added OICP tests
ADD
test/api/OICPEndpointTest.ts
+import { ReasonPhrases, StatusCodes } from 'http-status-codes';
+import chai, { expect } from 'chai';
+
+import CentralServerService from './client/CentralServerService';
+import ContextDefinition from './context/ContextDefinition';
+import ContextProvider from './context/ContextProvider';
+import Factory from '../factories/Factory';
+import OICPEndpoint from '../../src/types/oicp/OICPEndpoint';
+import TenantContext from './context/TenantContext';
+import User from '../../src/types/User';
+import chaiSubset from 'chai-subset';
+
+chai.use(chaiSubset);
+
+class TestData {
+ public centralUserService: CentralServerService;
+ public tenantContext: TenantContext;
+ public centralUserContext: any;
+ public userContext: User;
+ public newOcpiEndpoint: OICPEndpoint;
+}
+
+const testData: TestData = new TestData();
+
+describe('OICP Endpoint (utoicp)', function() {
+ this.timeout(30000);
+ before(async () => {
+ testData.tenantContext = await ContextProvider.defaultInstance.getTenantContext(ContextDefinition.TENANT_CONTEXTS.TENANT_OICP);
+ testData.centralUserContext = testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.DEFAULT_ADMIN);
+ testData.userContext = testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.DEFAULT_ADMIN);
+ expect(testData.userContext).to.not.be.null;
+ testData.centralUserService = new CentralServerService(
+ testData.tenantContext.getTenant().subdomain,
+ testData.centralUserContext
+ );
+ });
+
+ describe('Success cases', () => {
+ it('Should create a new OICP Endpoint', async () => {
+ // Create the entity
+ testData.newOcpiEndpoint = await testData.centralUserService.createEntity(
+ testData.centralUserService.oicpEndpointApi, Factory.oicpEndpoint.build({}));
+ });
+
+ it('Should find the created OICP Endpoint by id', async () => {
+ // Check if the created entity can be retrieved with its id
+ await testData.centralUserService.getEntityById(
+ testData.centralUserService.oicpEndpointApi, testData.newOcpiEndpoint);
+ });
+
+ it('Should find the created OICP Endpoint in the OICP Endpoint list', async () => {
+ // Check if the created entity is in the list
+ await testData.centralUserService.checkEntityInList(
+ testData.centralUserService.oicpEndpointApi, testData.newOcpiEndpoint);
+ });
+
+ it('Should register the created OICP Endpoint', async () => {
+ // Check if the deleted entity cannot be retrieved with its id
+ const response = await testData.centralUserService.oicpEndpointApi.register(testData.newOcpiEndpoint.id);
+ expect(response.status).to.be.equal(StatusCodes.OK);
+ expect(response.data.statusCode).to.be.equal(StatusCodes.OK);
+ expect(response.data.statusText).to.be.equal(ReasonPhrases.OK);
+ });
+
+ it('Should unregister the created OICP Endpoint', async () => {
+ // Check if the deleted entity cannot be retrieved with its id
+ const response = await testData.centralUserService.oicpEndpointApi.unregister(testData.newOcpiEndpoint.id);
+ expect(response.status).to.be.equal(StatusCodes.OK);
+ expect(response.data.statusCode).to.be.equal(StatusCodes.OK);
+ expect(response.data.statusText).to.be.equal(ReasonPhrases.OK);
+ });
+
+ it('Should update the OICP Endpoint', async () => {
+ // Change entity
+ testData.newOcpiEndpoint.name = 'NewName';
+ testData.newOcpiEndpoint.baseUrl = 'http://new.url/versions';
+ testData.newOcpiEndpoint.countryCode = 'FR';
+ testData.newOcpiEndpoint.partyId = 'AA';
+ // Update
+ await testData.centralUserService.updateEntity(
+ testData.centralUserService.oicpEndpointApi, testData.newOcpiEndpoint);
+ });
+
+ it('Should find the updated OICP Endpoint by id', async () => {
+ // Check if the updated entity can be retrieved with its id
+ const updatedOcpiEndpoint = await testData.centralUserService.getEntityById(
+ testData.centralUserService.oicpEndpointApi, testData.newOcpiEndpoint);
+ // Check
+ expect(updatedOcpiEndpoint.name).to.equal(testData.newOcpiEndpoint.name);
+ });
+
+ it('Should delete the created OICP Endpoint', async () => {
+ // Delete the created entity
+ await testData.centralUserService.deleteEntity(
+ testData.centralUserService.oicpEndpointApi, testData.newOcpiEndpoint);
+ });
+
+ it('Should not find the deleted OICP Endpoint with its id', async () => {
+ // Check if the deleted entity cannot be retrieved with its id
+ await testData.centralUserService.checkDeletedEntityById(
+ testData.centralUserService.oicpEndpointApi, testData.newOcpiEndpoint);
+ });
+ });
+});

MODIFY
test/api/client/CentralServerService.ts
test/api/client/CentralServerService.ts
@@ -14,6 +14,7 @@ import { HTTPError } from '../../../src/types/HTTPError';
import LogsApi from './LogsApi';
import MailApi from './MailApi';
import OCPIEndpointApi from './OCPIEndpointApi';
+import OICPEndpointApi from './OICPEndpointApi';
import RegistrationTokenApi from './RegistrationTokenApi';
import SettingApi from './SettingApi';
import SiteApi from './SiteApi';
@@ -51,6 +52,7 @@ export default class CentralServerService {
public transactionApi: TransactionApi;
public settingApi: SettingApi;
public ocpiEndpointApi: OCPIEndpointApi;
+ public oicpEndpointApi: OICPEndpointApi;
public authenticatedSuperAdminApi: AuthenticatedBaseApi;
public authenticationApi: AuthenticationApi;
public tenantApi: TenantApi;
@@ -102,6 +104,7 @@ export default class CentralServerService {
this.settingApi = new SettingApi(this.authenticatedApi);
this.logsApi = new LogsApi(this.authenticatedApi);
this.ocpiEndpointApi = new OCPIEndpointApi(this.authenticatedApi);
+ this.oicpEndpointApi = new OICPEndpointApi(this.authenticatedApi);
this.authenticationApi = new AuthenticationApi(this._baseApi);
this.tenantApi = new TenantApi(this.authenticatedSuperAdminApi, this._baseApi);
this.mailApi = new MailApi(new BaseApi(`http://${config.get('mailServer.host')}:${config.get('mailServer.port')}`));

ADD
test/api/client/OICPEndpointApi.ts
+import AuthenticatedBaseApi from './utils/AuthenticatedBaseApi';
+import CrudApi from './utils/CrudApi';
+import OCPIEndpoint from '../../../src/types/ocpi/OCPIEndpoint';
+import { ServerRoute } from '../../../src/types/Server';
+import TestConstants from './utils/TestConstants';
+
+export default class OICPEndpointApi extends CrudApi {
+ public constructor(authenticatedApi: AuthenticatedBaseApi) {
+ super(authenticatedApi);
+ }
+
+ public async readById(id: string) {
+ return super.readById(id, this.buildRestEndpointUrl(ServerRoute.REST_OICP_ENDPOINT, { id }));
+ }
+
+ public async readAll(params, paging = TestConstants.DEFAULT_PAGING, ordering = TestConstants.DEFAULT_ORDERING) {
+ return super.readAll(params, paging, ordering, this.buildRestEndpointUrl(ServerRoute.REST_OICP_ENDPOINTS));
+ }
+
+ public async create(data: OCPIEndpoint) {
+ return super.create(data, this.buildRestEndpointUrl(ServerRoute.REST_OICP_ENDPOINTS));
+ }
+
+ public async update(data: OCPIEndpoint) {
+ return super.update(data, this.buildRestEndpointUrl(ServerRoute.REST_OICP_ENDPOINT, { id: data.id }));
+ }
+
+ public async delete(id: string) {
+ return super.delete(id, this.buildRestEndpointUrl(ServerRoute.REST_OICP_ENDPOINT, { id }));
+ }
+
+ public async register(id: string) {
+ return super.update(id, this.buildRestEndpointUrl(ServerRoute.REST_OICP_ENDPOINT_REGISTER, { id }));
+ }
+
+ public async unregister(id: string) {
+ return super.update(id, this.buildRestEndpointUrl(ServerRoute.REST_OICP_ENDPOINT_UNREGISTER, { id }));
+ }
+}

MODIFY
test/api/context/ContextDefinition.ts
test/api/context/ContextDefinition.ts
@@ -12,6 +12,7 @@ export interface TenantDefinition {
componentSettings?: {
pricing?: { content?: SettingDBContent };
ocpi?: { content?: SettingDBContent };
+ oicp?: { content?: SettingDBContent };
organization?: { content?: SettingDBContent };
statistics?: { content?: SettingDBContent };
refund?: { content?: SettingDBContent };
@@ -31,6 +32,7 @@ export default class ContextDefinition {
TENANT_SIMPLE_PRICING: 'utpricing', // Only pricing component is active
TENANT_CONVERGENT_CHARGING: 'utconvcharg', // Only convergent charging component is active
TENANT_OCPI: 'utocpi', // Only ocpi component is active
+ TENANT_OICP: 'utoicp', // Only ocpi component is active
TENANT_FUNDING: 'utrefund', // Only refund component is active
TENANT_BILLING: 'utbilling', // Only billing and pricing component is active
TENANT_ASSET: 'utasset', // Only asset component is active
@@ -359,11 +361,39 @@ export default class ContextDefinition {
password: '',
stickyLimitation: true,
limitBufferDC: 20,
- limitBufferAC: 10, }
+ limitBufferAC: 10,
+ }
}
},
}
+ },
+ {
+ tenantName: ContextDefinition.TENANT_CONTEXTS.TENANT_OICP,
+ id: 'aaaaaaaaaaaaaaaaaaaaaab3',
+ subdomain: ContextDefinition.TENANT_CONTEXTS.TENANT_OICP,
+ componentSettings: {
+ oicp: {
+ content: {
+ type: RoamingSettingsType.OICP,
+ oicp: {
+ cpo: {
+ countryCode: 'FR',
+ partyID: 'UT',
+ },
+ emsp: {
+ countryCode: 'FR',
+ partyID: 'UT',
+ },
+ currency: 'EUR',
+ businessDetails: {
+ name: 'Test OICP',
+ website: 'http://www.utoicp.net'
}
+ }
+ }
+ },
+ },
+ },
];
// List of users created in a tenant

MODIFY
test/factories/Factory.ts
test/factories/Factory.ts
@@ -4,6 +4,7 @@ import CarFactory from './CarFactory';
import ChargingStationFactory from './ChargingStationFactory';
import CompanyFactory from './CompanyFactory';
import OcpiEndpointsFactory from './OcpiEndpointsFactory';
+import OicpEndpointsFactory from './OicpEndpointsFactory';
import RegistrationTokenFactory from './RegistrationTokenFactory';
import SettingFactory from './SettingFactory';
import SiteAreaFactory from './SiteAreaFactory';
@@ -23,6 +24,7 @@ export default abstract class Factory {
public static tenant = TenantFactory;
public static setting = SettingFactory;
public static ocpiEndpoint = OcpiEndpointsFactory;
+ public static oicpEndpoint = OicpEndpointsFactory;
public static car = CarFactory;
public static tag = TagFactory;
public static registrationToken = RegistrationTokenFactory;

ADD
test/factories/OicpEndpointsFactory.ts
+import { Factory } from 'rosie';
+import { OICPRole } from '../../src/types/oicp/OICPRole';
+import faker from 'faker';
+
+export default Factory.define('oicpEndpoint')
+ .attr('name', () => faker.name.lastName())
+ .attr('baseUrl', () => faker.internet.url())
+ .attr('countryCode', 'FR')
+ .attr('partyId', '107')
+ .attr('role', OICPRole.CPO);

Added OICP tests