Skip to content

Commit

Permalink
Merge pull request #3 from manuelseeger/moretests
Browse files Browse the repository at this point in the history
Moretests
  • Loading branch information
manuelseeger authored Jul 11, 2022
2 parents 6eee053 + 2aca681 commit 97f2f4f
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 21 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ In the first release this extension adds the capabilities listed below. Only sta
## Metadata Awareness
The extension provides basic IntelliSense for the OData query language based on service metadata.
### Metadata driven code completion
Provide basic Intellisense based on OData metadata:
Provide basic Intellisense based on OData metadata.

![odata-combine](./images/metadata-complete.gif)

### Metadata driven code navigation
Navigate to metadata definitions from entities and properties:
Navigate to metadata definitions from entities and properties.

![odata-combine](./images/metadata-definition.gif)

## Commands
Expand Down
Binary file modified images/metadata-complete.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 4 additions & 12 deletions src/odataCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function odataFormatUrl(text: string) {
.filter(t => !t.match(/^\s*\/\//))
// Remove extra whitespaces and join into a single line.
.map(t => t.trim())
.filter(t => t != '')
.join(' ')
// Make sure there are no spaces in the fragment part or the URI.
.replace(/\s+\?/, "?");
Expand Down Expand Up @@ -137,18 +138,9 @@ export function odataOpen() {
function getActiveRange(editor: TextEditor): Range {
let selection = editor.selection;
if (selection.isEmpty) {
// Empy selection indicates line selection mode.
let startLine = selection.start.line;
let endLine = selection.end.line;
// Extend selection to not-empty previous lines.
while (startLine > 0 && editor.document.lineAt(startLine - 1).isEmptyOrWhitespace == false) {
startLine -= 1;
}
// Extend selection to non-empty next lines.
while (endLine < editor.document.lineCount - 1 && editor.document.lineAt(endLine + 1).isEmptyOrWhitespace == false) {
endLine += 1;
}
return new Range(new Position(startLine, 0), editor.document.lineAt(endLine).range.end);
let firstLine = editor.document.lineAt(0);
let lastLine = editor.document.lineAt(editor.document.lineCount - 1);
return new Range(firstLine.range.start, lastLine.range.end);
} else {
return selection;
}
Expand Down
3 changes: 3 additions & 0 deletions src/odataCompletions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export class ODataDefaultCompletionItemProvider implements vscode.CompletionItem
if (document.getWordRangeAtPosition(position, /\$select=.*/)) {
return null;
}
if (document.getWordRangeAtPosition(position, /\/[a-zA-Z]*/)) {
return null;
}
if (document.getWordRangeAtPosition(position, /\$inlinecount=.*/)) {
return new CompletionList([new CompletionItem("allpages", CompletionItemKind.EnumMember)])
}
Expand Down
3 changes: 0 additions & 3 deletions src/test/fixtures/northwind$metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,6 @@
<Property Name="OrderID" Type="Edm.Int32" Nullable="false" />
<Property Name="Subtotal" Type="Edm.Decimal" Precision="19" Scale="4" />
</EntityType>
<Annotations Target="ODataWebExperimental.Northwind.Model.NorthwindEntities">
<Annotation Term="Com.Microsoft.OData.Service.Conventions.V1.UrlConventions" String="KeyAsSegment" />
</Annotations>
</Schema>
<Schema Namespace="ODataWebExperimental.Northwind.Model" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<EntityContainer Name="NorthwindEntities" p4:LazyLoadingEnabled="true" xmlns:p4="http://schemas.microsoft.com/ado/2009/02/edm/annotation">
Expand Down
5 changes: 5 additions & 0 deletions src/test/fixtures/northwind.odata
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
https://services.odata.org/V4/Northwind/Northwind.svc/Customers?
$select=CompanyName,ContactTitle,CustomerID
&$top=10
&$skip=10
&$expand=Orders($select=OrderID,CustomerID,Freight)
2 changes: 1 addition & 1 deletion src/test/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
const extensionDevelopmentPath = path.resolve(__dirname, '../../../');

// The path to the extension test script
// Passed to --extensionTestsPath
Expand Down
30 changes: 29 additions & 1 deletion src/test/suite/odataCommands.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,44 @@
import * as assert from 'assert';
import * as vscode from 'vscode';
import * as path from 'path';
import * as extension from '../../extension';

import { odataFormatUrl } from '../../odataCommands';

suite('OData Commands Tests', () => {
let odataQueryDocument = `https://my555555-sso.crm.ondemand.com/sap/c4c/odata-sso/v1/customer/IndividualCustomerCollection?

const testsPath = path.resolve(__dirname, '../');
const fixturesPath = path.join(testsPath, 'fixtures');

const odataQueryDocument = `https://my555555-sso.crm.ondemand.com/sap/c4c/odata-sso/v1/customer/IndividualCustomerCollection?
$filter=OwnerID eq '2341978'
&$select=FirstName,LastName,CustomerID
&$top=10
&$format=json
`
let combinedUrl = `https://my555555-sso.crm.ondemand.com/sap/c4c/odata-sso/v1/customer/IndividualCustomerCollection?%24format=json&%24filter=OwnerID+eq+%272341978%27&%24select=FirstName%2CLastName%2CCustomerID&%24top=10`

const northWindCombined = 'https://services.odata.org/V4/Northwind/Northwind.svc/Customers?%24expand=Orders%28%24select%3DOrderID%2CCustomerID%2CFreight%29&%24select=CompanyName%2CContactTitle%2CCustomerID&%24top=10&%24skip=10';

test('Can Format Url', () => {
assert.equal(odataFormatUrl(odataQueryDocument), combinedUrl)
})

test('Can run combine Url Command', async () => {
const uri = vscode.Uri.file(path.join(fixturesPath, 'northwind.odata'));
const document = await vscode.workspace.openTextDocument(uri);
const editor = await vscode.window.showTextDocument(document);
await sleep(200);
vscode.commands.executeCommand("odata.combine");
await sleep(1000);
const combinedText = editor.document.getText();
assert.equal(combinedText.trim(), northWindCombined)
vscode.commands.executeCommand("workbench.action.closeActiveEditor");
})
});

function sleep(ms: number): Promise<void> {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
4 changes: 2 additions & 2 deletions src/test/suite/odataMetadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ suite("Metadata Tests", () => {
let configuration = <odataMetadata.ODataMetadataConfiguration>{
map: [
{
url: 'https://services.odata.org/Experimental/Northwind/Northwind.svc',
url: 'https://services.odata.org/V4/Northwind/Northwind.svc',
path: path.join(fixturesPath, 'northwind$metadata.xml')
},
{
Expand All @@ -23,7 +23,7 @@ suite("Metadata Tests", () => {
const metadataService = new odataMetadata.LocalODataMetadataService(configuration);

test('Can parse Northwind', (done) => {
const metadata = metadataService.getMetadataDocument('https://services.odata.org/Experimental/Northwind/Northwind.svc');
const metadata = metadataService.getMetadataDocument('https://services.odata.org/V4/Northwind/Northwind.svc');
const containerEntities = metadata.getEntityContainerItems();
assert.equal(containerEntities.length, 26);
assert.ok(containerEntities.find(c => c.name == 'CustomerDemographics'));
Expand Down

0 comments on commit 97f2f4f

Please sign in to comment.