exchange-test-server

0.1.5 • Public • Published

exchange-test-server

NPM version Build Status Dependency Status Coverage Status

The test server that implement the EWS API

Install

$ npm install --save exchange-test-server

Usage

start the test server

server = new Server()
server.start {port: 3000}->
  console.log 'server listen on localhost:3000'

start the test server and send the SOAP request

Server = require 'exchange-test-server'
Builder = require 'libxmljs-builder'
http = require 'http'
NS =
  NS_SOAP: 'soap'
  NS_TYPES: 't'
  NS_MESSAGES: 'm'
  NAMESPACES:
    soap: 'http://schemas.xmlsoap.org/soap/envelope/'
    t: 'http://schemas.microsoft.com/exchange/services/2006/types'
    m: 'http://schemas.microsoft.com/exchange/services/2006/messages'
 
[NS_TNS_M] = [NS.NS_TYPESNS.NS_MESSAGES]
 
class RequestConstructor
  _build: (bodyCallback) ->
    @builder = new Builder
    @builder.defineNS NS.NAMESPACES
    @builder.rootNS NS.NS_SOAP'Envelope'(builder) ->
      builder.nodeNS NS.NS_SOAP'Body'bodyCallback
 
  _buildAction: (action, callback) ->
    @_build (builder) ->
      builder.nodeNS NS_Mactioncallback
 
  buildFolderIds: (builder, folderIds) ->
    folderIds = [folderIdsunless Array.isArray(folderIds)
    builder.nodeNS NS_M'FolderIds'(builder) =>
      @buildDistinguishFolderId(builderfolderId) for folderId in folderIds
 
  buildDistinguishFolderId: (builder, folderId) ->
    builder.nodeNS NS_T'DistinguishedFolderId'Id: folderId
 
class GetFolderRequest extends RequestConstructor
  build: (folderIds) ->
    @_buildAction 'GetFolder'(builder) =>
      builder.nodeNS NS_M'FolderShape'(builder) ->
        builder.nodeNS NS_T'BaseShape''Default'
      @buildFolderIds(builderfolderIds)
 
dbPath = require('path').resolve(__dirname'data/db.sqlite')
server = new Server()
server.start dbPath: dbPath->
  console.log 'server start'
 
  config =
    port: 3000method: 'POST'path: '/EWS/Exchange.asmx'
    headers: 'Content-Type': 'text/xml'
 
  req = http.request config(res) ->
    console.log 'Done'
    server.close()
  req.end new GetFolderRequest().build('inbox').toString()
 

API

(Coming soon)

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using gulp.

License

Copyright (c) 2015 liuxiong. Licensed under the MIT license.

Readme

Keywords

Package Sidebar

Install

npm i exchange-test-server

Weekly Downloads

1

Version

0.1.5

License

MIT

Last publish

Collaborators

  • liuxiong332